config.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """
  2. 应用配置:从 backend/.env 读取,含数据库、JWT、Neo4j、大模型与语音相关项。
  3. """
  4. from pathlib import Path
  5. from pydantic_settings import BaseSettings, SettingsConfigDict
  6. _BACKEND_DIR = Path(__file__).resolve().parents[2]
  7. _ENV_FILE = _BACKEND_DIR / ".env"
  8. class Settings(BaseSettings):
  9. model_config = SettingsConfigDict(env_file=str(_ENV_FILE), env_file_encoding="utf-8")
  10. app_name: str = "KnowMathBot API" #项目名
  11. api_v1_prefix: str = "/api/v1" #接口前缀
  12. #JWT登录认证
  13. jwt_secret_key: str = "CHANGE_ME_IN_ENV"
  14. jwt_algorithm: str = "HS256"
  15. access_token_exp_minutes: int = 60 * 24 #令牌有效期 1 天
  16. #数据库配置
  17. database_url: str = "sqlite:///./knowmathbot.db"
  18. #Neo4j知识图谱配置
  19. neo4j_uri: str = "neo4j://127.0.0.1:7687"
  20. neo4j_user: str = "neo4j"
  21. neo4j_password: str = "please_change_me"
  22. neo4j_database: str = "neo4j"
  23. #TTS语音合成配置
  24. local_tts_enabled: bool = False
  25. local_tts_model_dir: str = str(_BACKEND_DIR / "storage" / "tts")
  26. local_tts_ckpt_path: str = ""
  27. local_tts_pth_path: str = ""
  28. local_tts_provider: str = "pyttsx3"
  29. local_tts_api_url: str = ""
  30. local_tts_api_timeout_seconds: int = 60
  31. local_tts_ref_wav_path: str = ""
  32. local_tts_prompt_text: str = ""
  33. local_tts_prompt_lang: str = "zh"
  34. local_tts_text_lang: str = "zh"
  35. #外部大模型 API
  36. deepseek_api_key: str = ""
  37. deepseek_base_url: str = "https://api.deepseek.com"
  38. deepseek_model: str = "deepseek-chat"
  39. llm_request_timeout_seconds: int = 30
  40. voice_assets_dir: str = str(_BACKEND_DIR / "storage" / "voice_assets")
  41. settings = Settings()