feat: 完成AI模型清单后端
- 扩展 appconfig 读写 config/ai_models.json - 支持模型增删改、分类过滤、key 打码展示和 get_model 明文返回 - 增加模型唯一性、类别保底和测试连接错误返回 - 更新任务看板、模块合约、当前状态和进度记录
This commit is contained in:
+8
-3
@@ -34,17 +34,22 @@ response_timeout(config=None) -> int # = resolution_timeouts[resolutio
|
||||
|
||||
`config.json` 不保存 AI Key;写入 `api_key` / `*_key` / `token` / `password` 等敏感字段时抛 `ConfigError`。AI Key 留给 `config/ai_models.json`。
|
||||
|
||||
AI 模型清单(`config/ai_models.json`,含本地明文密钥;CRUD 由 ⑤ 设置,T-005 待建):
|
||||
AI 模型清单(`config/ai_models.json`,含本地明文密钥,已建;UI 由 ⑤ 设置复用):
|
||||
|
||||
```python
|
||||
list_ai_models(category=None) -> list[dict] # category=text/image 过滤;含 connect_timeout_seconds 等
|
||||
default_ai_models_config() -> dict
|
||||
load_ai_models_config(path="config/ai_models.json") -> dict # 不存在则写默认,至少 text/image 各一个
|
||||
save_ai_models_config(config, path="config/ai_models.json") -> dict
|
||||
list_ai_models(category=None) -> list[dict] # category=text/image 过滤;默认 api_key 打码,含 api_key_set
|
||||
add_ai_model(model) -> None # name 唯一校验
|
||||
update_ai_model(name, **fields) -> None
|
||||
delete_ai_model(name) -> None # 至少各留一个 text+image;删到剩一禁用
|
||||
test_ai_model(name) -> dict # 「测试连接」:用 key/url/model 发最小请求 -> {ok, error}
|
||||
test_ai_model(name) -> dict # 「测试连接」:用 key/url/model 发最小请求 -> {ok, status?, error?}
|
||||
get_model(name) -> dict # 返回模型定义,含 api_key(调用方不得写日志)
|
||||
```
|
||||
|
||||
`list_ai_models()` 用于 UI/API 展示,默认不返回明文 `api_key`;`get_model()` 用于实际调用 AI,返回明文 `api_key`,调用方不得写日志或导出。`test_ai_model()` 不记录密钥;缺少 `url/model/api_key` 时直接返回 `{ok: False, error: ...}`。
|
||||
|
||||
## db 模块(`app/db.py`,已建)
|
||||
|
||||
SQLite 读写,表见 [架构 5.2](04-architecture.md)。
|
||||
|
||||
Reference in New Issue
Block a user