mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-13 18:11:03 +08:00
[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:
@@ -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.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user