From a35f5366b87ed51f58a1c2fa771a75d778948101 Mon Sep 17 00:00:00 2001 From: yzlin Date: Mon, 5 Feb 2024 00:20:23 +0800 Subject: [PATCH] raise error directly if invalid json --- metagpt/provider/openai_api.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.py index 94aef70da..63e68c9bd 100644 --- a/metagpt/provider/openai_api.py +++ b/metagpt/provider/openai_api.py @@ -209,14 +209,7 @@ class OpenAILLM(BaseLLM): and message.tool_calls[0].function.arguments is not None ): # reponse is code - try: - return json.loads(message.tool_calls[0].function.arguments, strict=False) - except json.decoder.JSONDecodeError as e: - error_msg = ( - f"Got JSONDecodeError for \n{'--'*40} \n{message.tool_calls[0].function.arguments}, {str(e)}" - ) - logger.error(error_msg) - raise json.decoder.JSONDecodeError(error_msg, e.doc, e.pos) + return json.loads(message.tool_calls[0].function.arguments, strict=False) elif message.tool_calls is None and message.content is not None: # reponse is code, fix openai tools_call respond bug, # The response content is `code``, but it appears in the content instead of the arguments.