fix(llm-generator): resolve PR conflict and keep retry + JSON-repair + translation fallback

This commit is contained in:
nourzakhama2003 2025-12-22 02:57:37 +01:00
parent 3a717feab1
commit ce02e9ca27
1 changed files with 13 additions and 6 deletions

View File

@ -131,15 +131,22 @@ class LLMGenerator:
if cleaned_answer is None:
continue
# Parse JSON, try to repair malformed JSON if necessary
candidate = ""
try:
result_dict = json.loads(cleaned_answer)
candidate = result_dict.get("Your Output", "")
except json.JSONDecodeError:
logger.exception(
"Failed to parse LLM JSON when generating conversation name; "
"using raw query as fallback"
)
candidate = query
try:
result_dict = json_repair.loads(cleaned_answer)
except Exception:
logger.exception(
"Failed to parse LLM JSON when generating conversation name; using raw query as fallback"
)
candidate = query
else:
candidate = result_dict.get("Your Output", "")
else:
candidate = result_dict.get("Your Output", "")
# If input is Persian, ensure candidate contains Persian-specific characters.
# Otherwise retry with stronger instruction.