import os class BaseConfig: """ Base configuration class that holds default settings for the application. Environment-specific configurations will inherit from this class. """ PDF_FOLDER = os.getenv("PDF_FOLDER", "./app/pdfs") ENV = "base" OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "your-api-key-here") CREATE_FAISS_INDEX = True def __init__(self): """ Validates required configurations and ensures all necessary environment variables are set. """ if not self.OPENAI_API_KEY: raise ValueError("OPENAI_API_KEY environment variable must be set.") class DevelopmentConfig(BaseConfig): """ Configuration class for the development environment. Inherits defaults from BaseConfig. """ ENV = "development" DEBUG = True class ProductionConfig(BaseConfig): """ Configuration class for the production environment. Inherits defaults from BaseConfig but overrides production-specific settings. """ ENV = "production" DEBUG = False def get_config(env_name: str = "development"): """ Retrieves the appropriate configuration instance based on the environment name. :param env_name: Name of the environment (e.g., 'development', 'production'). :return: An instance of the selected configuration class. """ configs = { "development": DevelopmentConfig, "production": ProductionConfig, } config_class = configs.get(env_name.lower()) if not config_class: raise ValueError(f"Unknown environment '{env_name}'. Valid options are 'development' or 'production'.") config_instance = config_class() print(f"[INFO] Loaded configuration for environment: {config_instance.ENV}") return config_instance