update:完成Python部分的“动态更新web端的配置”

This commit is contained in:
CGD
2025-04-29 10:36:20 +08:00
parent f9f6a69c89
commit 361defc348
2 changed files with 27 additions and 0 deletions
+24
View File
@@ -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:
@@ -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)