|
|
"""Application configuration settings. |
|
|
|
|
|
This module handles all configuration settings loaded from environment variables. |
|
|
Settings are validated using Pydantic and cached for performance. |
|
|
""" |
|
|
|
|
|
from functools import lru_cache |
|
|
|
|
|
from pydantic import Field |
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict |
|
|
|
|
|
|
|
|
class Settings(BaseSettings): |
|
|
"""Application settings loaded from environment variables.""" |
|
|
|
|
|
model_config = SettingsConfigDict( |
|
|
env_file=".env", |
|
|
env_file_encoding="utf-8", |
|
|
extra="ignore", |
|
|
case_sensitive=False, |
|
|
) |
|
|
|
|
|
|
|
|
mongo_uri: str = Field( |
|
|
..., |
|
|
alias="MONGO_URI", |
|
|
description="MongoDB connection URI", |
|
|
) |
|
|
mongo_db: str = Field( |
|
|
"expense", |
|
|
alias="MONGO_DB", |
|
|
description="MongoDB database name", |
|
|
) |
|
|
mongo_collection: str = Field( |
|
|
"headcategories", |
|
|
alias="MONGO_COLLECTION", |
|
|
description="MongoDB collection name for headcategories", |
|
|
) |
|
|
mongo_subcategory_collection: str = Field( |
|
|
"categories", |
|
|
alias="MONGO_SUBCATEGORY_COLLECTION", |
|
|
description="MongoDB collection name for categories", |
|
|
) |
|
|
api_logs_collection: str = Field( |
|
|
"api_logs", |
|
|
alias="MONGO_API_LOGS_COLLECTION", |
|
|
description="MongoDB collection name for API logs", |
|
|
) |
|
|
|
|
|
|
|
|
openai_api_key: str = Field( |
|
|
..., |
|
|
alias="OPENAI_API_KEY", |
|
|
description="OpenAI API key for LLM requests", |
|
|
) |
|
|
openai_model: str = Field( |
|
|
"gpt-4o-mini", |
|
|
alias="OPENAI_MODEL", |
|
|
description="OpenAI model to use for categorization", |
|
|
) |
|
|
|
|
|
|
|
|
category_cache_ttl_seconds: int = Field( |
|
|
300, |
|
|
alias="CATEGORY_CACHE_TTL", |
|
|
description="Time-to-live for category cache in seconds (5 minutes default)", |
|
|
ge=60, |
|
|
) |
|
|
db_query_timeout_seconds: float = Field( |
|
|
5.0, |
|
|
alias="DB_QUERY_TIMEOUT", |
|
|
description="Timeout for database queries in seconds", |
|
|
ge=1.0, |
|
|
le=30.0, |
|
|
) |
|
|
openai_api_timeout_seconds: float = Field( |
|
|
15.0, |
|
|
alias="OPENAI_API_TIMEOUT", |
|
|
description="Timeout for OpenAI API calls in seconds", |
|
|
ge=5.0, |
|
|
le=60.0, |
|
|
) |
|
|
|
|
|
|
|
|
@lru_cache |
|
|
def get_settings() -> Settings: |
|
|
"""Get cached settings instance. |
|
|
|
|
|
Returns: |
|
|
Settings: Application settings instance |
|
|
""" |
|
|
return Settings() |
|
|
|
|
|
|
|
|
|
|
|
settings = get_settings() |
|
|
|