mirror of
https://github.com/FuQuan233/nonebot-plugin-llmchat.git
synced 2026-06-28 00:02:04 +00:00
🐛 修复工具调用参数解析错误,添加异常处理并记录警告信息
This commit is contained in:
parent
66f1f71a02
commit
975cc4705d
1 changed files with 14 additions and 1 deletions
|
|
@ -479,7 +479,20 @@ async def process_messages(context_id: int, is_group: bool = True):
|
|||
|
||||
for tool_call in message.tool_calls:
|
||||
tool_name = tool_call.function.name
|
||||
tool_args = json.loads(tool_call.function.arguments)
|
||||
try:
|
||||
tool_args = json.loads(tool_call.function.arguments)
|
||||
except (json.JSONDecodeError, TypeError, ValueError) as e:
|
||||
error_message = (
|
||||
f"工具调用参数格式错误,无法解析 {tool_name} 的 arguments: {e!s}. "
|
||||
f"原始参数: {tool_call.function.arguments}"
|
||||
)
|
||||
logger.warning(error_message)
|
||||
new_messages.append({
|
||||
"role": "tool",
|
||||
"tool_call_id": tool_call.id,
|
||||
"content": error_message,
|
||||
})
|
||||
continue
|
||||
|
||||
# 发送工具调用提示
|
||||
await handler.send(Message(f"正在使用{mcp_client.get_friendly_name(tool_name)}"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue