From 53d0e91d022e61adc4a25bee1da716a854bce7f3 Mon Sep 17 00:00:00 2001 From: Process Xie <530551426@qq.com> Date: Tue, 9 Dec 2025 20:18:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B7=A5=E5=85=B7=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E7=9A=84=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/llm_models/model_client/openai_client.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/llm_models/model_client/openai_client.py b/src/llm_models/model_client/openai_client.py index f573d33e..3d036ee2 100644 --- a/src/llm_models/model_client/openai_client.py +++ b/src/llm_models/model_client/openai_client.py @@ -437,8 +437,20 @@ def _default_normal_response_parser( for call in message_part.tool_calls: try: arguments = json.loads(repair_json(call.function.arguments)) + # 【新增修复逻辑】如果解析出来还是字符串,说明发生了双重编码,尝试二次解析 + if isinstance(arguments, str): + try: + # 尝试对字符串内容再次进行修复和解析 + arguments = json.loads(repair_json(arguments)) + except Exception: + # 如果二次解析失败,保留原值,让下方的 isinstance(dict) 抛出更具体的错误 + pass if not isinstance(arguments, dict): - raise RespParseException(resp, "响应解析失败,工具调用参数无法解析为字典类型") + # 此时为了调试方便,建议打印出 arguments 的类型 + raise RespParseException( + resp, + f"响应解析失败,工具调用参数无法解析为字典类型 type={type(arguments)} arguments={arguments}" + ) api_response.tool_calls.append(ToolCall(call.id, call.function.name, arguments)) except json.JSONDecodeError as e: raise RespParseException(resp, "响应解析失败,无法解析工具调用参数") from e