From 361defc3487ed481d976ae555fb0e4cbb57eec7f Mon Sep 17 00:00:00 2001 From: CGD <3030332422@qq.com> Date: Tue, 29 Apr 2025 10:36:20 +0800 Subject: [PATCH] =?UTF-8?q?update:=E5=AE=8C=E6=88=90Python=E9=83=A8?= =?UTF-8?q?=E5=88=86=E7=9A=84=E2=80=9C=E5=8A=A8=E6=80=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?web=E7=AB=AF=E7=9A=84=E9=85=8D=E7=BD=AE=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/connection.py | 24 +++++++++++++++++++ main/xiaozhi-server/core/handle/textHandle.py | 3 +++ 2 files changed, 27 insertions(+) diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index 3cf6b018..22b90313 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -214,6 +214,30 @@ class ConnectionHandler: elif isinstance(message, bytes): await handleAudioMessage(self, message) + async def handle_config_update(self, message): + """处理配置更新请求""" + config_model = message.get("model") + new_content = message.get("content") + + # 打印更新前的配置 + old_value = self.config.get(config_model) + self.logger.bind(tag=TAG).info(f"配置更新: {config_model} 从 {old_value} 更新为 {new_content}") + + # 更新配置 + self.config[config_model] = new_content + + # 如果是模型相关配置,重新初始化模型 + if config_model in ["LLM", "TTS", "ASR", "VAD", "Intent", "Memory"]: + self._initialize_components(self.config) + self.logger.bind(tag=TAG).info(f"已使用新配置重新初始化 {config_model} 模块") + + # 返回更新确认 + await self.websocket.send(json.dumps({ + "type": "config_update_response", + "status": "success", + "message": f"{config_model} 配置已更新" + })) + def _initialize_components(self, private_config): """初始化组件""" if private_config is not None: diff --git a/main/xiaozhi-server/core/handle/textHandle.py b/main/xiaozhi-server/core/handle/textHandle.py index 43e980e8..f65d436a 100644 --- a/main/xiaozhi-server/core/handle/textHandle.py +++ b/main/xiaozhi-server/core/handle/textHandle.py @@ -61,5 +61,8 @@ async def handleTextMessage(conn, message): asyncio.create_task(handleIotDescriptors(conn, msg_json["descriptors"])) if "states" in msg_json: asyncio.create_task(handleIotStatus(conn, msg_json["states"])) + elif msg_json["type"] == "server": + if "model" in msg_json: + await conn.handle_config_update(msg_json) except json.JSONDecodeError: await conn.websocket.send(message)