LiKenun's picture
Update documentation and environment variables configuration
3da2136
raw
history blame
2.18 kB
from loguru import logger
from pydantic import Field, MongoDsn, NonNegativeFloat, NonNegativeInt, PositiveInt, SecretStr
from pydantic_settings import BaseSettings, SettingsConfigDict
from types import MappingProxyType
from typing import Literal, Mapping, Optional, Self
class Settings(BaseSettings):
"""
Application settings loaded from environment variables.
"""
def __init__(self: Self, **data) -> None:
super().__init__(**data)
logger.debug("Created {}", self.__class__.__name__)
if self.__pydantic_extra__:
logger.warning("Extra unrecognized environment variables were provided: {}", ", ".join(self.__pydantic_extra__))
# Logging Configuration ― not actually used to configure Loguru, but defined to prevent warnings about “unknown” environment variables
LOG_LEVEL: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = Field(default_factory=lambda data: "DEBUG" if data.get("DEBUG", False) else "INFO")
LOG_FORMAT: Literal["text", "json"] = "json"
# APScheduler Configuration
SCHEDULER_TIMEZONE: Optional[str] = "UTC"
# Slack Configuration
SLACK_BOT_TOKEN: SecretStr
SLACK_APP_TOKEN: SecretStr
# Vectorization Configuration
EMBEDDING_MODEL: str
VECTOR_DIMENSION: PositiveInt
CHUNK_SIZE: PositiveInt
CHUNK_OVERLAP: NonNegativeInt
TOP_K_MATCHES: PositiveInt
# MongoDB Configuration
MONGODB_URI: SecretStr # TODO: Contemplate switching to MongoDsn type for the main URL, and separate out the credentials to SecretStr variables.
MONGODB_NAME: str
SCORE_THRESHOLD: NonNegativeFloat
# Hugging Face Configuration
HF_API_TOKEN: Optional[SecretStr] = None
# OpenAI Configuration
OPENAI_API_KEY: SecretStr
CHAT_MODEL: str
MAX_TOKENS: PositiveInt
TEMPERATURE: NonNegativeFloat
SYSTEM_PROMPT: str
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=True,
extra="allow",
frozen=True
)
def get_extra_environment_variables(self: Self) -> Mapping[str, str]:
return MappingProxyType(self.__pydantic_extra__)