Skip to content

Commit 61c071e

Browse files
authored
[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. 🎉
1 parent 66c7127 commit 61c071e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

backend/src/module/parser/analyser/openai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def parse(
104104

105105
if asdict:
106106
try:
107-
result = json.loads(result)
107+
result = json.loads(result[result.index("{"):result.rindex("}") + 1]) # find the first { and last } for better compatibility
108108
except json.JSONDecodeError:
109109
logger.warning(f"Cannot parse result {result} as python dict.")
110110

0 commit comments

Comments
 (0)