Merge pull request #1068 from xinnan-tech/py-update-config

update:python部分"动态更新配置"的优化
This commit is contained in:
Sakura-RanChen
2025-04-30 11:57:09 +08:00
committed by GitHub
2 changed files with 11 additions and 2 deletions
+9 -2
View File
@@ -42,9 +42,10 @@ class TTSException(RuntimeError):
class ConnectionHandler:
def __init__(
self, config: Dict[str, Any], _vad, _asr, _llm, _tts, _memory, _intent
self, config: Dict[str, Any], _vad, _asr, _llm, _tts, _memory, _intent, server=None
):
self.config = copy.deepcopy(config)
self.config = config
self.server = server
self.logger = setup_logging()
self.auth = AuthMiddleware(config)
@@ -256,6 +257,12 @@ class ConnectionHandler:
if config_model in ["llm", "tts", "asr", "vad", "intent", "memory"]:
updated_modules.append(config_model)
# 同步更新 WebSocketServer 的配置
if self.server:
async with self.server.config_lock: # 使用锁确保线程安全
for config_model in updated_modules:
self.server.config[config_model].update(new_config[config_model])
# 批量初始化模块
if updated_modules:
try:
@@ -11,6 +11,7 @@ class WebSocketServer:
def __init__(self, config: dict):
self.config = config
self.logger = setup_logging()
self.config_lock = asyncio.Lock()
modules = initialize_modules(
self.logger, self.config, True, True, True, True, True, True
)
@@ -43,6 +44,7 @@ class WebSocketServer:
self._tts,
self._memory,
self._intent,
self # 传入当前 WebSocketServer 实例
)
self.active_connections.add(handler)
try: