feat: 添加任务类型和能力字段至模型配置,增强模型初始化逻辑

This commit is contained in:
墨梓柒
2025-07-29 09:57:20 +08:00
parent 254958fe85
commit 7313529dcb
4 changed files with 201 additions and 20 deletions

View File

@@ -85,7 +85,7 @@ class APIProvider:
# 如果所有key都不可用返回当前key让上层处理
return api_key
def reset_key_failures(self, api_key: str = None):
def reset_key_failures(self, api_key: str | None = None):
"""重置失败计数(成功调用后调用)"""
with self._lock:
if api_key and api_key in self.api_keys:
@@ -124,6 +124,10 @@ class ModelInfo:
price_out: float = 0.0 # 每M token输出价格
force_stream_mode: bool = False # 是否强制使用流式输出模式
# 新增:任务类型和能力字段
task_type: str = "" # 任务类型llm_normal, llm_reasoning, vision, embedding, speech
capabilities: List[str] = field(default_factory=list) # 模型能力text, vision, embedding, speech, tool_calling, reasoning
@dataclass

View File

@@ -162,6 +162,8 @@ def _models(parent: Dict, config: ModuleConfig):
price_in = model.get("price_in", 0.0)
price_out = model.get("price_out", 0.0)
force_stream_mode = model.get("force_stream_mode", False)
task_type = model.get("task_type", "")
capabilities = model.get("capabilities", [])
if name in config.models: # 查重
logger.error(f"重复的模型名称: {name},请检查配置文件。")
@@ -181,6 +183,8 @@ def _models(parent: Dict, config: ModuleConfig):
price_in=price_in,
price_out=price_out,
force_stream_mode=force_stream_mode,
task_type=task_type,
capabilities=capabilities,
)
else:
logger.error(f"模型 '{name}' 的配置不完整,请检查配置文件。")