12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- # -*- coding: utf-8 -*-
- import os
- from pydantic import (
- AnyHttpUrl,
- BaseSettings,
- DirectoryPath,
- PostgresDsn,
- SecretStr,
- validator,
- )
- class Settings(BaseSettings):
- # SERVER_NAME: str
- # SERVER_HOST: AnyHttpUrl
- PLATFORM_HOST: AnyHttpUrl
- PLATFORM_SECRET: SecretStr
- TRANSFER_HOST: AnyHttpUrl
- CUSTOM_HOST: AnyHttpUrl
- # WEATHER_HOST: AnyHttpUrl
- # HTTPS_PROXY: AnyHttpUrl
- TENCENT_NLP_ENDPOINT: str
- TENCENT_SECRET_ID_V1: str
- TENCENT_SECRET_KEY_V1: str
- DUCKLING_HOST: AnyHttpUrl
- # PROJECT_DIR: DirectoryPath
- # LOGS_DIR: DirectoryPath
- ML_MODELS_DIR: DirectoryPath
- PROJECT_NAME: str
- REDIS_HOST: str
- REDIS_PORT: int
- REDIS_DB: int
- REDIS_PASSWORD: str
- MILVUS_HOST: str | None
- MILVUS_PORT: str | None
- METRIC_TYPE: str | None
- VECTOR_DIMENSION: int | None
- POSTGRES_SERVER: str
- POSTGRES_USER: str
- POSTGRES_PASSWORD: str
- POSTGRES_DB: str
- SQLALCHEMY_DATABASE_URL: PostgresDsn | None
- NEED_MILVUS: str
- @validator("SQLALCHEMY_DATABASE_URL", pre=True)
- def assemble_db_connection(cls, v: str | None, values: dict[str, str | int | bool]):
- if isinstance(v, str):
- return v
- return PostgresDsn.build(
- scheme="postgresql",
- # user=values.get("POSTGRES_USER"),
- user=os.getenv("POSTGRES_USER", values.get("POSTGRES_USER")),
- # password=values.get("POSTGRES_PASSWORD"),
- password=os.getenv("POSTGRES_PASSWORD", values.get("POSTGRES_PASSWORD")),
- # host=values.get("POSTGRES_SERVER"),
- host=os.getenv("POSTGRES_SERVER", values.get("POSTGRES_SERVER")),
- # path=f'/{values.get("POSTGRES_DB") or ""}',
- path=f'/{os.getenv("POSTGRES_DB", values.get("POSTGRES_DB")) or ""}',
- )
- class Config:
- case_sensitive = True
- env_file = ".env"
- settings = Settings()
|