From 549ac7c6cf58fd4d020078d44e5c313c07bab76a Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Sat, 29 Mar 2025 17:46:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/__init__.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/config/__init__.py b/src/config/__init__.py index 0682393d..c78efc8d 100644 --- a/src/config/__init__.py +++ b/src/config/__init__.py @@ -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")