yonnel
Enhance environment configuration; implement lazy initialization for vector updater and improve error handling in imports
b8ca8ae
"""
Settings and environment configuration
"""
import os
from functools import lru_cache
from pydantic_settings import BaseSettings
from typing import Optional
class Settings(BaseSettings):
"""Application settings"""
# OpenAI API key for embeddings
openai_api_key: str
# TMDB API key for movie data
tmdb_api_key: str
# API authentication token
api_token: str
# Environment (dev/prod)
env: str = "dev"
# Logging level
log_level: str = "INFO"
# Filter adult content (True = exclude adult films, False = include all)
filter_adult_content: Optional[str] = "true"
# Hugging Face configuration
hf_token: str = ""
hf_dataset_repo: str = ""
# Vector update configuration
auto_update_vectors: Optional[str] = "true"
update_interval_hours: int = 24
batch_size: int = 100
max_movies_limit: int = 10000
# Admin configuration
admin_token: str = ""
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
@property
def filter_adult_content_bool(self) -> bool:
"""Parse filter_adult_content as boolean"""
if isinstance(self.filter_adult_content, str):
# Remove any comments and strip whitespace
value = self.filter_adult_content.split('#')[0].strip().lower()
return value in ('true', '1', 'yes', 'on')
return bool(self.filter_adult_content)
@property
def auto_update_vectors_bool(self) -> bool:
"""Parse auto_update_vectors as boolean"""
if isinstance(self.auto_update_vectors, str):
# Remove any comments and strip whitespace
value = self.auto_update_vectors.split('#')[0].strip().lower()
return value in ('true', '1', 'yes', 'on')
return bool(self.auto_update_vectors)
@lru_cache()
def get_settings() -> Settings:
"""Get cached settings instance"""
return Settings()