config.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. "azure": {
  18. "api_key": "your-azure-api-key",
  19. "api_base": "https://your-azure-endpoint.openai.azure.com",
  20. "model_name": "gpt-35-turbo",
  21. "temperature": 0,
  22. "max_tokens": 2000
  23. },
  24. "local": {
  25. "api_key": "your-local-api-key",
  26. "api_base": "http://localhost:8000/v1",
  27. "model_name": "local-model",
  28. "temperature": 0,
  29. "max_tokens": 2000
  30. }
  31. }
  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])