@@ -378,12 +378,20 @@ def run_with_rag(title: str, description: str) -> List[str]:
378378 List of tags
379379 """
380380 try :
381- # Load tags from JSON file with better error handling
381+ # Look for tags.json in the current directory and in the discussion_labeler directory
382382 tags_file_path = Path ("tags.json" )
383383 if not tags_file_path .exists ():
384- logger .error ("tags.json file not found" )
385- return []
384+ # Try with discussion_labeler prefix
385+ tags_file_path = Path ("discussion_labeler/tags.json" )
386+ if not tags_file_path .exists ():
387+ # Try with the absolute path from the current directory
388+ current_dir = Path (__file__ ).resolve ().parent
389+ tags_file_path = current_dir / "tags.json"
390+ if not tags_file_path .exists ():
391+ logger .error (f"tags.json file not found - searched in current dir, discussion_labeler/, and { current_dir } " )
392+ return []
386393
394+ logger .info (f"Loading tags from: { tags_file_path } " )
387395 with open (tags_file_path , "r" ) as f :
388396 tags_data = json .load (f )
389397
@@ -411,39 +419,87 @@ def run_with_rag(title: str, description: str) -> List[str]:
411419 # Combine search results with the original description
412420 augmented_description = description + "\n \n " + "\n " .join (tag_strings )
413421
414- # Execute the Prompty file
422+ # Execute the Prompty file - look in multiple directories
415423 prompty_file_path = Path ("basic.prompty" )
424+ prompty_file_name = "basic.prompty"
425+
416426 if not prompty_file_path .exists ():
417- logger .error ("basic.prompty file not found" )
418- return []
427+ # Try with discussion_labeler prefix
428+ prompty_file_path = Path ("discussion_labeler/basic.prompty" )
429+ prompty_file_name = "discussion_labeler/basic.prompty"
419430
431+ if not prompty_file_path .exists ():
432+ # Try with the absolute path from the current directory
433+ current_dir = Path (__file__ ).resolve ().parent
434+ prompty_file_path = current_dir / "basic.prompty"
435+ prompty_file_name = str (prompty_file_path )
436+
437+ if not prompty_file_path .exists ():
438+ logger .error (f"basic.prompty file not found - searched in current dir, discussion_labeler/, and { current_dir } " )
439+ return []
440+
441+ logger .info (f"Using prompty file from: { prompty_file_path } " )
420442 raw = prompty .execute (
421- "basic.prompty" ,
443+ prompty_file_name ,
422444 inputs = {
423445 "title" : title ,
424446 "tags" : azure_tags ,
425447 "description" : augmented_description
426448 }
427449 )
428450
451+ # Enhanced debugging for prompty output
452+ logger .info (f"Raw output from prompty: { raw } " )
453+
429454 # Parse prompty's JSON output
430455 try :
456+ if not raw or raw .strip () == "None" or raw .strip () == "null" :
457+ logger .error ("Empty or null response from prompty" )
458+ return []
459+
431460 parsed = json .loads (raw )
461+ logger .info (f"Parsed output type: { type (parsed )} , value: { parsed } " )
462+
432463 # If prompty returns a bare list:
433464 if isinstance (parsed , list ):
434- return [str (item ) for item in parsed ] # Ensure all items are strings
465+ result = [str (item ) for item in parsed ] # Ensure all items are strings
466+ logger .info (f"Returning tag list: { result } " )
467+ return result
468+
435469 # If it returns {"tags": [...]}:
436470 if isinstance (parsed , dict ):
437471 tags = parsed .get ("tags" , [])
438- return [str (item ) for item in tags ] # Ensure all items are strings
472+ result = [str (item ) for item in tags ] # Ensure all items are strings
473+ logger .info (f"Returning tags from dict: { result } " )
474+ return result
475+
476+ logger .error (f"Unexpected parsed output format: { parsed } " )
477+ return []
439478
440479 except json .JSONDecodeError as e :
441480 logger .error (f"Could not parse RAG output: { e } " )
442- logger .debug (f"RAG raw output: { raw } " )
481+ logger .error (f"RAG raw output: { raw } " )
482+
483+ # Try to return any valid strings that might be in the output
484+ if raw and isinstance (raw , str ):
485+ # Try to clean the output if it looks like it might contain tags
486+ if "[" in raw and "]" in raw :
487+ try :
488+ # Extract the part between [ and ]
489+ tag_part = raw [raw .find ("[" ): raw .rfind ("]" ) + 1 ]
490+ cleaned = json .loads (tag_part )
491+ if isinstance (cleaned , list ):
492+ logger .info (f"Recovered tags from malformed output: { cleaned } " )
493+ return [str (item ) for item in cleaned ]
494+ except :
495+ pass
443496
444497 except Exception as e :
445498 logger .error (f"Error in run_with_rag: { str (e )} " )
499+ import traceback
500+ logger .error (traceback .format_exc ())
446501
502+ logger .warning ("Returning empty tag list due to errors or no matches" )
447503 return []
448504
449505@trace
@@ -612,9 +668,17 @@ def process_discussions(repo: str = None) -> None:
612668 Args:
613669 repo: Repository URL in the format "owner/name" (optional)
614670 """
671+ # Set the working directory to the script's location to ensure relative paths work
672+ script_dir = Path (__file__ ).resolve ().parent
673+ os .chdir (script_dir )
674+ logger .info (f"Working directory set to: { os .getcwd ()} " )
675+
615676 if not repo :
616677 repo = DEFAULT_REPO
617-
678+
679+ logger .info (f"Processing discussions for repo: { repo } " )
680+ logger .info (f"Using GitHub App ID: { APP_ID } " )
681+
618682 try :
619683 # Validate GitHub App configuration
620684 validate_github_app_config ()
0 commit comments