mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
fix: get_config_from_api_async只拿到custom_config,需传入default_config才能合并Memory段
This commit is contained in:
parent
17f465ff12
commit
e3b288cf29
2 changed files with 18 additions and 16 deletions
|
|
@ -340,6 +340,8 @@ Memory:
|
||||||
# 检索模式: fts5(关键词), embedding(语义), hybrid(混合)
|
# 检索模式: fts5(关键词), embedding(语义), hybrid(混合)
|
||||||
retrieval_mode: fts5
|
retrieval_mode: fts5
|
||||||
# 危险行为检测通知(可选),检测到儿童危险行为时推送
|
# 危险行为检测通知(可选),检测到儿童危险行为时推送
|
||||||
|
# 通知API:POST /api/v1/internal/messages/event
|
||||||
|
# 认证方式:Header x-api-key
|
||||||
danger_alert:
|
danger_alert:
|
||||||
api_url: "http://your-api-host/api/v1/internal/messages/event"
|
api_url: "http://your-api-host/api/v1/internal/messages/event"
|
||||||
api_key: "your-internal-api-key"
|
api_key: "your-internal-api-key"
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,11 @@ def load_config():
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
# 如果已经在事件循环中,使用异步版本
|
# 如果已经在事件循环中,使用异步版本
|
||||||
config = asyncio.run_coroutine_threadsafe(
|
config = asyncio.run_coroutine_threadsafe(
|
||||||
get_config_from_api_async(custom_config), loop
|
get_config_from_api_async(custom_config, default_config), loop
|
||||||
).result()
|
).result()
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
# 如果不在事件循环中(启动时),创建新的事件循环
|
# 如果不在事件循环中(启动时),创建新的事件循环
|
||||||
config = asyncio.run(get_config_from_api_async(custom_config))
|
config = asyncio.run(get_config_from_api_async(custom_config, default_config))
|
||||||
else:
|
else:
|
||||||
# 合并配置
|
# 合并配置
|
||||||
config = merge_configs(default_config, custom_config)
|
config = merge_configs(default_config, custom_config)
|
||||||
|
|
@ -61,10 +61,10 @@ def load_config():
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
async def get_config_from_api_async(config):
|
async def get_config_from_api_async(custom_config, default_config):
|
||||||
"""从Java API获取配置(异步版本)"""
|
"""从Java API获取配置(异步版本)"""
|
||||||
# 初始化API客户端
|
# 初始化API客户端
|
||||||
init_service(config)
|
init_service(custom_config)
|
||||||
|
|
||||||
# 获取服务器配置
|
# 获取服务器配置
|
||||||
config_data = await get_server_config()
|
config_data = await get_server_config()
|
||||||
|
|
@ -73,26 +73,26 @@ async def get_config_from_api_async(config):
|
||||||
|
|
||||||
config_data["read_config_from_api"] = True
|
config_data["read_config_from_api"] = True
|
||||||
config_data["manager-api"] = {
|
config_data["manager-api"] = {
|
||||||
"url": config["manager-api"].get("url", ""),
|
"url": custom_config["manager-api"].get("url", ""),
|
||||||
"secret": config["manager-api"].get("secret", ""),
|
"secret": custom_config["manager-api"].get("secret", ""),
|
||||||
}
|
}
|
||||||
auth_enabled = config_data.get("server", {}).get("auth", {}).get("enabled", False)
|
auth_enabled = config_data.get("server", {}).get("auth", {}).get("enabled", False)
|
||||||
# server的配置以本地为准
|
# server的配置以本地为准
|
||||||
if config.get("server"):
|
if custom_config.get("server"):
|
||||||
config_data["server"] = {
|
config_data["server"] = {
|
||||||
"ip": config["server"].get("ip", ""),
|
"ip": custom_config["server"].get("ip", ""),
|
||||||
"port": config["server"].get("port", ""),
|
"port": custom_config["server"].get("port", ""),
|
||||||
"http_port": config["server"].get("http_port", ""),
|
"http_port": custom_config["server"].get("http_port", ""),
|
||||||
"vision_explain": config["server"].get("vision_explain", ""),
|
"vision_explain": custom_config["server"].get("vision_explain", ""),
|
||||||
"auth_key": config["server"].get("auth_key", ""),
|
"auth_key": custom_config["server"].get("auth_key", ""),
|
||||||
}
|
}
|
||||||
config_data["server"]["auth"] = {"enabled": auth_enabled}
|
config_data["server"]["auth"] = {"enabled": auth_enabled}
|
||||||
# 如果服务器没有prompt_template,则从本地配置读取
|
# 如果服务器没有prompt_template,则从本地配置读取
|
||||||
if not config_data.get("prompt_template"):
|
if not config_data.get("prompt_template"):
|
||||||
config_data["prompt_template"] = config.get("prompt_template")
|
config_data["prompt_template"] = default_config.get("prompt_template")
|
||||||
# 合并本地 Memory 配置(如 danger_alert),通过 type 字段匹配模型 key
|
# 合并本地 Memory 配置(如 danger_alert),通过 type 字段匹配模型 key
|
||||||
if config.get("Memory") and config_data.get("Memory"):
|
if default_config.get("Memory") and config_data.get("Memory"):
|
||||||
local_memory = config["Memory"]
|
local_memory = default_config["Memory"]
|
||||||
for api_key, api_val in config_data["Memory"].items():
|
for api_key, api_val in config_data["Memory"].items():
|
||||||
if not isinstance(api_val, dict):
|
if not isinstance(api_val, dict):
|
||||||
continue
|
continue
|
||||||
|
|
@ -158,7 +158,7 @@ def ensure_directories(config):
|
||||||
provider_config = config.get(module_type, {}).get(selected_provider, {})
|
provider_config = config.get(module_type, {}).get(selected_provider, {})
|
||||||
output_dir = provider_config.get("output_dir")
|
output_dir = provider_config.get("output_dir")
|
||||||
if output_dir:
|
if output_dir:
|
||||||
full_model_dir = os.path.join(project_dir, output_dir)
|
full_model_dir = os.path.join(project_dir, output_dir)
|
||||||
dirs_to_create.add(full_model_dir)
|
dirs_to_create.add(full_model_dir)
|
||||||
|
|
||||||
# 统一创建目录(保留原data目录创建)
|
# 统一创建目录(保留原data目录创建)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue