config.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from typing import Dict, Any
  2. from pydantic import BaseModel
  3. import os
  4. from dotenv import load_dotenv
  5. # 加载config.env文件
  6. load_dotenv("config.env")
  7. class ModelConfig(BaseModel):
  8. """AI模型配置类"""
  9. api_key: str
  10. api_base: str
  11. model_name: str
  12. temperature: float = 0
  13. max_tokens: int = 2000
  14. # AI模型配置
  15. model_list: Dict[str, Dict[str, Any]] = {
  16. "openai": {
  17. "api_key": "none",
  18. "api_base": "http://ac.zjugis.com:8511/v1",
  19. "model_name": "qwen2.5-instruct"
  20. },
  21. "zjstai": {
  22. "api_key": "none",
  23. "api_base": "http://172.27.27.72:1025/v1",
  24. "model_name": "DeepSeek-R1-Distill-Qwen-32B",
  25. }
  26. }
  27. # 从环境变量获取默认模型类型,如果未设置则使用"openai"作为默认值
  28. DEFAULT_MODEL_TYPE = os.getenv("DEFAULT_MODEL_TYPE", "openai")
  29. def get_model_config(model_type: str = "openai") -> ModelConfig:
  30. """
  31. 获取模型配置
  32. :param model_type: 模型类型,默认为openai
  33. :return: 模型配置对象
  34. """
  35. if model_type not in model_list:
  36. raise ValueError(f"Unsupported model type: {model_type}")
  37. return ModelConfig(**model_list[model_type])