修复第一次添加自定义模型导致的问题

This commit is contained in:
Wenjie Zhang 2025-03-29 17:46:19 +08:00
parent 3e51d604e0
commit 549ac7c6cf

View File

@ -108,9 +108,14 @@ class Config(SimpleConfig):
self.model_name = self.get("model_name") or default_model_name
else:
self.model_name = self.get("model_name")
if self.model_name not in [item["custom_id"] for item in self.custom_models]:
if self.model_name not in [item["custom_id"] for item in self.get("custom_models", [])]:
logger.warning(f"Model name {self.model_name} not in custom models, using default model name")
self.model_name = self.custom_models[0]["custom_id"]
if self.get("custom_models", []):
self.model_name = self.get("custom_models", [])[0]["custom_id"]
else:
self.model_name = self._config_items["model_name"]["default"]
self.model_provider = self._config_items["model_provider"]["default"]
logger.error(f"No custom models found, using default model {self.model_name} from {self.model_provider}")
# 检查模型提供商的环境变量
conds = {}
@ -180,21 +185,21 @@ class Config(SimpleConfig):
"""
获取安全的配置即过滤掉 api_key
"""
config = json.loads(str(self))
# 过滤掉 api_key
for model in config.get("custom_models", []):
model["api_key"] = DEFAULT_MOCK_API if model.get("api_key") else ""
return config
def compare_custom_models(self, value):
"""
比较 custom_models 中的 api_key如果输入的 api_key 与当前的 api_key 相同则不修改
如果输入的 api_key DEFAULT_MOCK_API则使用当前的 api_key
"""
current_models_dict = {model["custom_id"]: model.get("api_key") for model in self.custom_models}
current_models_dict = {model["custom_id"]: model.get("api_key") for model in self.get("custom_models", [])}
for i, model in enumerate(value):
input_custom_id = model.get("custom_id")