config.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """
  2. HealthAgent 核心配置模块
  3. """
  4. from dataclasses import dataclass, field
  5. from typing import Optional
  6. import os
  7. from dotenv import load_dotenv
  8. load_dotenv()
  9. # ========== LLM ==========
  10. @dataclass
  11. class LLMConfig:
  12. model_name: str = field(
  13. default_factory=lambda: os.getenv("OPENAI_MODEL_ID", "qwen-turbo")
  14. )
  15. api_key: Optional[str] = field(
  16. default_factory=lambda: os.getenv("OPENAI_API_KEY")
  17. )
  18. base_url: Optional[str] = field(
  19. default_factory=lambda: os.getenv("OPENAI_BASE_URL")
  20. )
  21. temperature: float = 0.7
  22. max_tokens: int = 2048
  23. timeout: int = 60
  24. # ========== Agent ==========
  25. @dataclass
  26. class AgentConfig:
  27. max_steps: int = 5
  28. timeout: int = 300
  29. history_limit: int = 50
  30. # ========== RAG ==========
  31. @dataclass
  32. class RAGConfig:
  33. enabled: bool = False
  34. top_k: int = 5
  35. # ========== App ==========
  36. @dataclass
  37. class AppConfig:
  38. app_name: str = "HealthRecordAgent"
  39. debug: bool = False
  40. log_level: str = "INFO"
  41. # ========== Main ==========
  42. @dataclass
  43. class HealthAgentConfig:
  44. app: AppConfig = field(default_factory=AppConfig)
  45. llm: LLMConfig = field(default_factory=LLMConfig)
  46. agent: AgentConfig = field(default_factory=AgentConfig)
  47. rag: RAGConfig = field(default_factory=RAGConfig)
  48. # 全局配置
  49. _config = HealthAgentConfig()
  50. def get_config() -> HealthAgentConfig:
  51. return _config