fix: 修复review反馈——fields追加式更新与占位符判定

This commit is contained in:
Sakura-RanChen 2026-11-02 11:09:40 +08:00
parent 5f6e191d11
commit c282397cd2
2 changed files with 12 additions and 7 deletions

View file

@ -1,13 +1,17 @@
-- 为Ollama LLM配置补充api_key键,用于鉴权网关/Ollama Cloud场景
-- 仅在未设置时添加占位值,不覆盖用户已有配置;本地Ollama无需鉴权,保持默认即可
-- Ollama LLM配置补充api_key占位值,走鉴权网关/Ollama Cloud时使用
UPDATE `ai_model_config`
SET `config_json` = JSON_SET(`config_json`, '$.api_key', 'ollama')
WHERE `id` = 'LLM_OllamaLLM' AND JSON_EXTRACT(`config_json`, '$.api_key') IS NULL;
-- 为Ollama供应商补充api_key字段定义,使管理后台新增/编辑Ollama模型时可直接填写API密钥
-- 仅在fields中尚无api_key时更新,不覆盖其他自定义字段
-- Ollama供应商追加api_key字段定义,password类型
UPDATE `ai_model_provider`
SET `fields` = '[{"key":"model_name","label":"模型名称","type":"string"},{"key":"base_url","label":"服务地址","type":"string"},{"key":"api_key","label":"API密钥","type":"string"}]'
SET `fields` = JSON_ARRAY_APPEND(COALESCE(`fields`, JSON_ARRAY()), '$',
JSON_OBJECT('key', 'api_key', 'label', 'API密钥', 'type', 'password'))
WHERE `id` = 'SYSTEM_LLM_ollama'
AND JSON_SEARCH(`fields`, 'one', 'api_key', NULL, '$[*].key') IS NULL;
-- 配置说明补充api_key条目
UPDATE `ai_model_config`
SET `remark` = CONCAT(`remark`, '\n4. 走鉴权网关或使用Ollama Cloud时,需填写api_key')
WHERE `id` = 'LLM_OllamaLLM'
AND `remark` IS NOT NULL AND `remark` NOT LIKE '%api_key%';

View file

@ -184,7 +184,8 @@ def get_provider_type(module: str, provider_name: str | None = None) -> str | No
def has_real_key(config: dict, *keys: str) -> bool:
"""任一候选 key 名下值不是占位符就算有真密钥。
占位符判定:空 / "你的..." / 包含 "placeholder" / 字面 "none"。
占位符判定:空 / "你的..." / 包含 "placeholder" / 字面 "none" / "ollama"
(Ollama本地服务无需鉴权,config.yaml默认占位值即为"ollama")。
"""
if not config:
return False
@ -193,7 +194,7 @@ def has_real_key(config: dict, *keys: str) -> bool:
if val is None:
continue
s = str(val).strip().lower()
if not s or s == "none":
if not s or s == "none" or s == "ollama":
continue
if s.startswith("你的") or "placeholder" in s:
continue