From fd4193daab533a2c69da56b69398c8019169cd03 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Mon, 2 Jun 2025 21:06:51 +0800 Subject: [PATCH 1/3] fix:local variable 'response' referenced before assignment --- main/xiaozhi-server/core/api/vision_handler.py | 11 +++++++---- main/xiaozhi-server/core/handle/helloHandle.py | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) 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 ) From 6bf6159e6cbfb3484de3b6c0a851d532fb7d7c0f Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Mon, 2 Jun 2025 21:15:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?update:=E6=9B=B4=E6=96=B0hamcp=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/homeassistant-integration.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/homeassistant-integration.md b/docs/homeassistant-integration.md index 3142244e..474049c1 100644 --- a/docs/homeassistant-integration.md +++ b/docs/homeassistant-integration.md @@ -202,7 +202,15 @@ change_role;get_weather;get_news;play_music;hass_get_state;hass_set_state #### 2. 配置小智开源服务端MCP配置信息 -切换到小智开源服务端`xiaozhi-esp32-server`的`mcp_server_settings.json`文件内,在`"mcpServers"`的括号内添加以下内容: + +进入`data`目录,找到`.mcp_server_settings.json`文件。 + +如果你的`data`目录下没有`.mcp_server_settings.json`文件, +- 请把在`xiaozhi-server`文件夹根目录的`mcp_server_settings.json`文件复制到`data`目录下,并重命名为`.mcp_server_settings.json` +- 或[下载这个文件](https://github.com/xinnan-tech/xiaozhi-esp32-server/blob/main/main/xiaozhi-server/mcp_server_settings.json),下载到`data`目录下,并重命名为`.mcp_server_settings.json` + + +修改`"mcpServers"`里的这部分的内容: ```json "Home Assistant": { From c0d4bbcecffda6a23cc14270521d86a9693c3a24 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Mon, 2 Jun 2025 21:24:26 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=86=E5=B8=83?= =?UTF-8?q?=E5=BC=8F=E9=83=A8=E7=BD=B2=E6=97=B6jwt=E5=AF=86=E9=92=A5?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/app.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main/xiaozhi-server/app.py b/main/xiaozhi-server/app.py index 8c8a728b..2088e183 100644 --- a/main/xiaozhi-server/app.py +++ b/main/xiaozhi-server/app.py @@ -46,8 +46,13 @@ async def main(): check_ffmpeg_installed() config = load_config() - # 生成随机密钥并添加到配置中 - config["server"]["auth_key"] = str(uuid.uuid4().hex) + # 默认使用manager-api的secret作为auth_key + # 如果secret为空,则生成随机密钥 + # auth_key用于jwt认证,比如视觉分析接口的jwt认证 + auth_key = config.get("manager-api", {}).get("secret", "") + if not auth_key or len(auth_key) == 0 or "你" in auth_key: + auth_key = str(uuid.uuid4().hex) + config["server"]["auth_key"] = auth_key # 添加 stdin 监控任务 stdin_task = asyncio.create_task(monitor_stdin())