config.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from typing import Dict, Any
  2. from pydantic import BaseModel
  3. class ModelConfig(BaseModel):
  4. """AI模型配置类"""
  5. api_key: str
  6. api_base: str
  7. model_name: str
  8. temperature: float = 0
  9. max_tokens: int = 2000
  10. # AI模型配置
  11. model_list: Dict[str, Dict[str, Any]] = {
  12. "openai": {
  13. "api_key": "none",
  14. "api_base": "http://ac.zjugis.com:8511/v1",
  15. "model_name": "qwen2.5-instruct"
  16. },
  17. "zjstai": {
  18. "api_key": "none",
  19. "api_base": "http://172.27.27.20:20331/v1",
  20. "model_name": "DeepSeek-R1-Distill-Qwen-32B",
  21. }
  22. }
  23. # 新增全局默认模型类型开关
  24. DEFAULT_MODEL_TYPE = "openai"
  25. # # 线上服务器配置
  26. # DEFAULT_MODEL_TYPE = "zjstai"
  27. def get_model_config(model_type: str = "openai") -> ModelConfig:
  28. """
  29. 获取模型配置
  30. :param model_type: 模型类型,默认为openai
  31. :return: 模型配置对象
  32. """
  33. if model_type not in model_list:
  34. raise ValueError(f"Unsupported model type: {model_type}")
  35. return ModelConfig(**model_list[model_type])