|
|
|
|
|
import os |
|
|
from functools import lru_cache |
|
|
|
|
|
|
|
|
try: |
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict |
|
|
from pydantic import AnyUrl, Field |
|
|
IS_V2 = True |
|
|
except Exception: |
|
|
from pydantic import BaseSettings, AnyUrl |
|
|
from pydantic import Field |
|
|
IS_V2 = False |
|
|
|
|
|
class Settings(BaseSettings): |
|
|
|
|
|
AMQP_URL: AnyUrl = Field(..., description="amqps://user:pass@host:5671/%2F?heartbeat=30") |
|
|
|
|
|
RABBIT_INSTANCE_NAME: str = "prod" |
|
|
RABBIT_EXCHANGE_TYPE: str = "topic" |
|
|
RABBIT_ROUTING_KEY: str = "" |
|
|
RABBIT_PREFETCH: int = 1 |
|
|
|
|
|
SERVICE_ID: str = "gradllm" |
|
|
USE_TLS: bool = True |
|
|
|
|
|
|
|
|
EXCHANGE_TYPES: dict[str, str] = {} |
|
|
|
|
|
if IS_V2: |
|
|
|
|
|
model_config = SettingsConfigDict( |
|
|
case_sensitive=True, |
|
|
env_file=".env", |
|
|
env_file_encoding="utf-8", |
|
|
) |
|
|
else: |
|
|
|
|
|
class Config: |
|
|
case_sensitive = True |
|
|
env_file = ".env" |
|
|
env_file_encoding = "utf-8" |
|
|
|
|
|
@lru_cache |
|
|
def get_settings() -> Settings: |
|
|
try: |
|
|
return Settings() |
|
|
except Exception as e: |
|
|
|
|
|
raise RuntimeError( |
|
|
"AMQP_URL is not set or invalid. In your Hugging Face Space, add a Secret " |
|
|
"named AMQP_URL (e.g. amqps://user:pass@host:5671/%2F?heartbeat=30)." |
|
|
) from e |
|
|
|
|
|
settings = get_settings() |
|
|
|