22from enum import Enum
33from typing import Annotated , Any , List , Literal , Optional
44
5- from pydantic import AnyUrl , BeforeValidator , HttpUrl , PostgresDsn
6- from pydantic_core import MultiHostUrl
5+ from pydantic import AnyUrl , BeforeValidator , HttpUrl
76from pydantic_settings import BaseSettings
87
98
@@ -18,6 +17,15 @@ def parse_cors(v: Any) -> List[str] | str:
1817 raise ValueError (v )
1918
2019
20+ def replace_postgresql_asyncpg (url : str ) -> str :
21+ """
22+ Replaces `postgresql://` with `postgresql+asyncpg://` in the URL.
23+ """
24+ if "postgresql://" in url :
25+ return url .replace ("postgresql://" , "postgresql+asyncpg://" )
26+ return url
27+
28+
2129class AppEnvironment (str , Enum ):
2230 """
2331 Enum for app environments.
@@ -36,6 +44,7 @@ class ApplicationSetting(BaseSettings):
3644 PROJECT_NAME : str = "QLLM"
3745 API_PREFIX : str = "/api/v1"
3846 SECRET_KEY : str = secrets .token_urlsafe (32 )
47+ PORT : int = 10000
3948 ACCESS_TOKEN_EXPIRE_MINUTES : int = 11520
4049 UVICORN_WORKER_COUNT : Optional [int ] = None
4150 BACKEND_CORS_ORIGINS : Annotated [
@@ -53,7 +62,7 @@ class ApplicationSetting(BaseSettings):
5362 ALGORITHM : str = "HS256"
5463
5564 # Database config
56- DATABASE_URL : str
65+ DATABASE_URL : Annotated [ str , BeforeValidator ( replace_postgresql_asyncpg )]
5766
5867 # LLM Config
5968 LLM_TEMPERATURE : float = 0.5
0 commit comments