[fix] better json parsing in openai.py (#913)

Thanks for the contribution\! This fix helps users who use alternative GPT APIs like Moonshot that don't support structured output mode. 🎉
This commit is contained in:
Leohearts
2026-01-26 05:12:38 +08:00
committed by GitHub
parent 66c7127f21
commit 61c071e035

View File

@@ -104,7 +104,7 @@ class OpenAIParser:
if asdict:
try:
result = json.loads(result)
result = json.loads(result[result.index("{"):result.rindex("}") + 1]) # find the first { and last } for better compatibility
except json.JSONDecodeError:
logger.warning(f"Cannot parse result {result} as python dict.")