mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-24 04:19:48 +01:00
现象:provider 构造期报
TypeError: argument of type 'NoneType' is not iterable
而且栈顶落在 core/utils/util.py 的 check_model_key,看不出是哪个模块的
key 没配。智控台下发的配置里未必带 api_key 字段(本地 LLM 场景也常把
它留空),HA 插件配置没填 api_key 时同样中招:hass_state 和
hass_play_music 都调 initialize_hass_handler,整个插件初始化被打断。
原因:check_model_key 直接写 ``"你" in modelKey``,modelKey 为 None 时
这行就炸了;modelKey 为空串时则静默返回 None,等于没检查。
改法:先把 None / 空串当成「未设置」处理,返回提示文案而不是抛异常。
if not modelKey:
return f"配置错误: {modelType} 的 API key 未设置"
出厂占位符的分支保持原样,提示文案里仍带当前值,方便用户对照改。
测试:
- 新增 tests/core/utils/test_check_model_key.py:缺 key / 占位符 / 真 key
三种情况的契约
- tests/plugins_func/test_hass_init.py 补一条端到端:插件配置里没有
api_key 时 initialize_hass_handler 不再崩
- 全量 pytest tests/ -q 无新增失败
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
||
|---|---|---|
| .. | ||
| config | ||
| core | ||
| plugins_func | ||
| __init__.py | ||
| conftest.py | ||
| test_llm.py | ||
| test_manage_api_client_lifecycle.py | ||
| test_memory.py | ||
| test_rag.py | ||
| test_smoke.py | ||
| test_stt.py | ||
| test_tts.py | ||