diff --git a/main/xiaozhi-server/core/api/vision_handler.py b/main/xiaozhi-server/core/api/vision_handler.py index e0f7096a..168440e4 100644 --- a/main/xiaozhi-server/core/api/vision_handler.py +++ b/main/xiaozhi-server/core/api/vision_handler.py @@ -37,17 +37,19 @@ class VisionHandler: async def handle_post(self, request): """处理 MCP Vision POST 请求""" + response = None # 初始化response变量 try: # 验证token is_valid, token_device_id = self._verify_auth_token(request) if not is_valid: - return web.Response( + response = web.Response( text=json.dumps( self._create_error_response("无效的认证token或token已过期") ), content_type="application/json", status=401, ) + return response # 获取请求头信息 device_id = request.headers.get("Device-Id", "") @@ -120,11 +122,11 @@ class VisionHandler: vllm_type, current_config["VLLM"][select_vllm_module] ) - response = vllm.response(question, image_base64) + result = vllm.response(question, image_base64) return_json = { "success": True, - "result": response, + "result": result, } response = web.Response( @@ -146,7 +148,8 @@ class VisionHandler: content_type="application/json", ) finally: - self._add_cors_headers(response) + if response: + self._add_cors_headers(response) return response async def handle_get(self, request): diff --git a/main/xiaozhi-server/core/handle/helloHandle.py b/main/xiaozhi-server/core/handle/helloHandle.py index adf835ca..6b8cb4fd 100644 --- a/main/xiaozhi-server/core/handle/helloHandle.py +++ b/main/xiaozhi-server/core/handle/helloHandle.py @@ -74,6 +74,8 @@ async def checkWakeupWords(conn, text): text_hello = WAKEUP_CONFIG["text"] if not text_hello: text_hello = text + if conn.tts is None: + return False conn.tts.tts_one_sentence( conn, ContentType.FILE, content_file=file, content_detail=text_hello )