from pydantic_settings import BaseSettings from functools import lru_cache import os from dotenv import load_dotenv load_dotenv() class Settings(BaseSettings): """ Lưu trữ và quản lý cấu hình ứng dụng từ biến môi trường. Các thuộc tính: facebook_verify_token, facebook_app_secret, ... """ # Facebook Configuration facebook_verify_token: str = os.getenv("FACEBOOK_VERIFY_TOKEN") or "" facebook_app_secret: str = os.getenv("FACEBOOK_APP_SECRET") or "" # Google Sheets Configuration google_sheets_credentials_file: str = os.getenv("GOOGLE_SHEETS_CREDENTIALS_FILE") or "" google_sheets_token_file: str = os.getenv("GOOGLE_SHEETS_TOKEN_FILE") or "" conversation_sheet_id: str = os.getenv("CONVERSATION_SHEET_ID") or "" # Supabase Configuration supabase_url: str = os.getenv("SUPABASE_URL") or "" supabase_key: str = os.getenv("SUPABASE_KEY") or "" # Server Configuration host: str = os.getenv("HOST", "0.0.0.0") or "" port: int = int(os.getenv("PORT", "8000")) or 8000 # Logging Configuration log_level: str = os.getenv("LOG_LEVEL", "INFO") or "INFO" class Config: env_file = ".env" @lru_cache() def get_settings() -> Settings: """ Lấy instance Settings đã cache (singleton). Input: None Output: Settings instance. """ return Settings()