config.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # -*- coding: utf-8 -*-
  2. import os
  3. from pydantic import (
  4. AnyHttpUrl,
  5. BaseSettings,
  6. DirectoryPath,
  7. PostgresDsn,
  8. SecretStr,
  9. validator,
  10. )
  11. class Settings(BaseSettings):
  12. # SERVER_NAME: str
  13. # SERVER_HOST: AnyHttpUrl
  14. PLATFORM_HOST: AnyHttpUrl
  15. PLATFORM_SECRET: SecretStr
  16. TRANSFER_HOST: AnyHttpUrl
  17. CUSTOM_HOST: AnyHttpUrl
  18. # WEATHER_HOST: AnyHttpUrl
  19. # HTTPS_PROXY: AnyHttpUrl
  20. TENCENT_NLP_ENDPOINT: str
  21. TENCENT_SECRET_ID_V1: str
  22. TENCENT_SECRET_KEY_V1: str
  23. DUCKLING_HOST: AnyHttpUrl
  24. # PROJECT_DIR: DirectoryPath
  25. # LOGS_DIR: DirectoryPath
  26. ML_MODELS_DIR: DirectoryPath
  27. PROJECT_NAME: str
  28. REDIS_HOST: str
  29. REDIS_PORT: int
  30. REDIS_DB: int
  31. REDIS_PASSWORD: str
  32. MILVUS_HOST: str | None
  33. MILVUS_PORT: str | None
  34. METRIC_TYPE: str | None
  35. VECTOR_DIMENSION: int | None
  36. POSTGRES_SERVER: str
  37. POSTGRES_USER: str
  38. POSTGRES_PASSWORD: str
  39. POSTGRES_DB: str
  40. SQLALCHEMY_DATABASE_URL: PostgresDsn | None
  41. NEED_MILVUS: str
  42. @validator("SQLALCHEMY_DATABASE_URL", pre=True)
  43. def assemble_db_connection(cls, v: str | None, values: dict[str, str | int | bool]):
  44. if isinstance(v, str):
  45. return v
  46. return PostgresDsn.build(
  47. scheme="postgresql",
  48. # user=values.get("POSTGRES_USER"),
  49. user=os.getenv("POSTGRES_USER", values.get("POSTGRES_USER")),
  50. # password=values.get("POSTGRES_PASSWORD"),
  51. password=os.getenv("POSTGRES_PASSWORD", values.get("POSTGRES_PASSWORD")),
  52. # host=values.get("POSTGRES_SERVER"),
  53. host=os.getenv("POSTGRES_SERVER", values.get("POSTGRES_SERVER")),
  54. # path=f'/{values.get("POSTGRES_DB") or ""}',
  55. path=f'/{os.getenv("POSTGRES_DB", values.get("POSTGRES_DB")) or ""}',
  56. )
  57. class Config:
  58. case_sensitive = True
  59. env_file = ".env"
  60. settings = Settings()