添加API密钥管理功能,包括获取、更新和验证API密钥的接口,增强了对Mathpix和其他API的支持;优化了设置面板的用户体验,改进了API密钥的状态显示和编辑功能,确保用户能够方便地管理和验证API密钥。

This commit is contained in:
Zylan
2025-04-02 21:56:38 +08:00
parent cebfaba26c
commit a46b8ac229
10 changed files with 2516 additions and 476 deletions

View File

@@ -98,36 +98,26 @@ class ModelFactory:
@classmethod
def create_model(cls, model_name: str, api_key: str, temperature: float = 0.7, system_prompt: str = None, language: str = None) -> BaseModel:
"""
Create and return an instance of the specified model.
Create a model instance based on the model name.
Args:
model_name: The identifier of the model to create
api_key: The API key for the model
temperature: Optional temperature parameter for response generation
system_prompt: Optional custom system prompt
language: Optional language preference for responses
model_name: The identifier for the model
api_key: The API key for the model service
temperature: The temperature to use for generation
system_prompt: The system prompt to use
language: The preferred language for responses
Returns:
An instance of the specified model
Raises:
ValueError: If the model_name is not recognized
A model instance
"""
model_info = cls._models.get(model_name)
if not model_info:
if model_name not in cls._models:
raise ValueError(f"Unknown model: {model_name}")
model_info = cls._models[model_name]
model_class = model_info['class']
# 对于Mathpix模型不传递language参数
if model_name == 'mathpix':
return model_class(
api_key=api_key,
temperature=temperature,
system_prompt=system_prompt
)
else:
# 对于所有其他模型传递model_name参数
# 对于DeepSeek模型需要传递正确的模型名称
if 'deepseek' in model_name.lower():
return model_class(
api_key=api_key,
temperature=temperature,
@@ -135,6 +125,30 @@ class ModelFactory:
language=language,
model_name=model_name
)
# 对于阿里巴巴模型,也需要传递正确的模型名称
elif 'qwen' in model_name.lower() or 'qvq' in model_name.lower() or 'alibaba' in model_name.lower():
return model_class(
api_key=api_key,
temperature=temperature,
system_prompt=system_prompt,
language=language,
model_name=model_name
)
# 对于Mathpix模型不传递language参数
elif model_name == 'mathpix':
return model_class(
api_key=api_key,
temperature=temperature,
system_prompt=system_prompt
)
else:
# 其他模型仅传递标准参数
return model_class(
api_key=api_key,
temperature=temperature,
system_prompt=system_prompt,
language=language
)
@classmethod
def get_available_models(cls) -> list[Dict[str, Any]]: