From 62d9a84babe36525a6c8d94e0db4041b0d689660 Mon Sep 17 00:00:00 2001 From: KawakazeNotFound Date: Thu, 6 Nov 2025 16:33:41 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E5=9C=A8?= =?UTF-8?q?=E9=95=BF=E6=96=87=E6=9C=AC=E4=B8=8B=E5=AE=B9=E6=98=93=E8=A7=A6?= =?UTF-8?q?=E5=8F=91tool=5Fcall=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_llmchat/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nonebot_plugin_llmchat/__init__.py b/nonebot_plugin_llmchat/__init__.py index a6246f8..947c3b3 100755 --- a/nonebot_plugin_llmchat/__init__.py +++ b/nonebot_plugin_llmchat/__init__.py @@ -453,7 +453,7 @@ async def process_messages(context_id: int, is_group: bool = True): message = response.choices[0].message # 处理响应并处理工具调用 - while preset.support_mcp and message.tool_calls: + while preset.support_mcp and message and message.tool_calls: new_messages.append({ "role": "assistant", "tool_calls": [tool_call.model_dump() for tool_call in message.tool_calls] @@ -505,11 +505,17 @@ async def process_messages(context_id: int, is_group: bool = True): message = response.choices[0].message + # 安全检查:确保 message 不为 None + if not message: + logger.error("API 响应中的 message 为 None") + await handler.send(Message("服务暂时不可用,请稍后再试")) + return + reply, matched_reasoning_content = pop_reasoning_content( - response.choices[0].message.content + message.content ) reasoning_content: str | None = ( - getattr(response.choices[0].message, "reasoning_content", None) + getattr(message, "reasoning_content", None) or matched_reasoning_content ) @@ -518,7 +524,7 @@ async def process_messages(context_id: int, is_group: bool = True): "content": reply, } - reply_images = getattr(response.choices[0].message, "images", None) + reply_images = getattr(message, "images", None) if reply_images: # openai的sdk里的assistant消息暂时没有images字段,需要单独处理