config.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from pydantic_settings import BaseSettings
  2. from functools import lru_cache
  3. from pathlib import Path
  4. import os
  5. def _find_env_file():
  6. candidates = [Path.cwd() / ".env", Path(__file__).resolve().parent.parent.parent.parent / ".env"]
  7. for p in candidates:
  8. if p.exists():
  9. return str(p)
  10. return ".env"
  11. class Settings(BaseSettings):
  12. app_name: str = "PharmacopoeiaAI"
  13. app_env: str = "development"
  14. app_debug: bool = True
  15. secret_key: str = "change-me"
  16. api_prefix: str = "/api/v1"
  17. postgres_host: str = "localhost"
  18. postgres_port: int = 5432
  19. postgres_db: str = "pharmacopoeia"
  20. postgres_user: str = "postgres"
  21. postgres_password: str = "postgres"
  22. redis_host: str = "localhost"
  23. redis_port: int = 6379
  24. redis_password: str = ""
  25. redis_db: int = 0
  26. milvus_host: str = "localhost"
  27. milvus_port: int = 19530
  28. milvus_collection: str = "drug_entries"
  29. llm_provider: str = "qwen"
  30. qwen_api_key: str = ""
  31. qwen_base_url: str = "https://dashscope.aliyuncs.com/compatible-mode/v1"
  32. qwen_model: str = "qwen-max"
  33. qwen_max_tokens: int = 4096
  34. qwen_temperature: float = 0.1
  35. qwen_local_base_url: str = "http://localhost:8000/v1"
  36. qwen_local_model: str = "Qwen3-35B-A3B"
  37. embedding_model: str = "BAAI/bge-m3"
  38. embedding_dim: int = 1024
  39. embedding_device: str = "cpu"
  40. reranker_model: str = "BAAI/bge-reranker-v2-m3"
  41. wechat_appid: str = ""
  42. wechat_secret: str = ""
  43. rate_limit_per_minute: int = 60
  44. rate_limit_per_hour: int = 1000
  45. log_level: str = "INFO"
  46. log_file: str = "logs/app.log"
  47. @property
  48. def database_url(self) -> str:
  49. return (
  50. f"postgresql+asyncpg://{self.postgres_user}:{self.postgres_password}"
  51. f"@{self.postgres_host}:{self.postgres_port}/{self.postgres_db}"
  52. )
  53. @property
  54. def database_url_sync(self) -> str:
  55. return (
  56. f"postgresql://{self.postgres_user}:{self.postgres_password}"
  57. f"@{self.postgres_host}:{self.postgres_port}/{self.postgres_db}"
  58. )
  59. model_config = {"env_file": _find_env_file(), "case_sensitive": False, "extra": "ignore"}
  60. @lru_cache
  61. def get_settings() -> Settings:
  62. return Settings()