From 1a31c8cd1d4099238104d505881ab1bad94acb06 Mon Sep 17 00:00:00 2001 From: Sakura-RanChen <1908198662@qq.com> Date: Tue, 17 Jun 2025 16:13:24 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E8=A7=86=E8=A7=89=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=AF=86=E5=88=AB=E8=BE=93=E5=87=BA=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E7=BB=8F=E8=BF=87=E4=BA=8C=E6=AC=A1LLM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiaozhi-server/core/api/vision_handler.py | 4 +++- main/xiaozhi-server/core/connection.py | 21 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/main/xiaozhi-server/core/api/vision_handler.py b/main/xiaozhi-server/core/api/vision_handler.py index 55dd22a3..70be247a 100644 --- a/main/xiaozhi-server/core/api/vision_handler.py +++ b/main/xiaozhi-server/core/api/vision_handler.py @@ -8,6 +8,7 @@ from config.config_loader import get_private_config_from_api from core.utils.auth import AuthToken import base64 from typing import Tuple, Optional +from plugins_func.register import Action TAG = __name__ @@ -122,7 +123,8 @@ class VisionHandler: return_json = { "success": True, - "result": result, + "action": Action.RESPONSE.name, + "response": result, } response = web.Response( diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index 60a7a283..7928d1cf 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -751,9 +751,24 @@ class ConnectionHandler: self.loop, ).result() self.logger.bind(tag=TAG).debug(f"MCP工具调用结果: {result}") - result = ActionResponse( - action=Action.REQLLM, result=result, response="" - ) + + if isinstance(result, str): + try: + result = json.loads(result) + except Exception as e: + self.logger.bind(tag=TAG).error(f"解析MCP工具返回结果失败: {e}") + + # 视觉大模型不经过二次LLM处理 + if isinstance(result, dict) and "action" in result: + result = ActionResponse( + action=Action[result["action"]], + result=None, + response=result.get("response", "") + ) + else: + result = ActionResponse( + action=Action.REQLLM, result=result, response="" + ) except Exception as e: self.logger.bind(tag=TAG).error(f"MCP工具调用失败: {e}") result = ActionResponse(