fix: strip markdown code fences from LLM responses before json.loads
- glm-5.2 returns JSON wrapped in ```json ... ``` code fences - Added fence stripping in services.py, query_understanding.py, jobs.py
This commit is contained in:
@@ -225,6 +225,12 @@ async def deep_analysis(
|
||||
content = response.choices[0].message.content
|
||||
if not content:
|
||||
return
|
||||
# Strip markdown code fences if present
|
||||
content = content.strip()
|
||||
if content.startswith("```"):
|
||||
content = content.split("\n", 1)[-1] if "\n" in content else content[3:]
|
||||
if content.endswith("```"):
|
||||
content = content[:-3].strip()
|
||||
suggestion_data = json.loads(content)
|
||||
if not suggestion_data.get("title") or not suggestion_data.get("content"):
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user