config.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. "local": {
  23. "api_key": "your-local-api-key",
  24. "api_base": "http://localhost:8000/v1",
  25. "model_name": "local-model",
  26. "temperature": 0,
  27. "max_tokens": 2000
  28. }
  29. }
  30. # 新增全局默认模型类型开关
  31. DEFAULT_MODEL_TYPE = "openai"
  32. def get_model_config(model_type: str = "openai") -> ModelConfig:
  33. """
  34. 获取模型配置
  35. :param model_type: 模型类型,默认为openai
  36. :return: 模型配置对象
  37. """
  38. if model_type not in model_list:
  39. raise ValueError(f"Unsupported model type: {model_type}")
  40. return ModelConfig(**model_list[model_type])