"""Configuration module for the multi-agent system.""" import os import logging from pathlib import Path from pydantic_settings import BaseSettings from env_loader import EnvironmentLoader, validate_on_startup logger = logging.getLogger(__name__) # Validate secrets on startup validate_on_startup() class Settings(BaseSettings): """Application settings loaded from environment variables.""" # DashScope Configuration (Aliyun Qwen) - loaded from environment openrouter_api_key: str = "" openrouter_base_url: str = "" model_name: str = "qwen3.7-plus" # Hugging Face Configuration huggingface_token: str = "" huggingface_dataset: str = "factorstudios/Pipeline" huggingface_api_url: str = "https://huggingface.co/api" # System Configuration data_dir: str = "./data" output_dir: str = "./output" log_dir: str = "./logs" port: int = 7860 # All agents run on this single port host: str = "0.0.0.0" # Agent Endpoints (all on port 7860) # POST /api/agents/showrunner # POST /api/agents/story-editor # POST /api/agents/cultural-consultant # POST /api/agents/lead-writer # POST /api/agents/dialogue-specialist # POST /api/agents/comedy-writer # POST /api/agents/proofreader # POST /api/pipeline/execute # GET /api/pipeline/status/{run_id} # Logging log_level: str = "INFO" class Config: env_file = ".env" case_sensitive = False extra = "allow" # Allow extra fields protected_namespaces = ('settings_',) # Allow model_ namespace def __init__(self, **data): # Load DashScope credentials from environment if not data.get("openrouter_api_key"): data["openrouter_api_key"] = os.getenv("DASHSCOPE_API_KEY", "") if not data.get("openrouter_base_url"): data["openrouter_base_url"] = os.getenv( "DASHSCOPE_BASE_URL", "https://dashscope.aliyuncs.com/compatible-mode/v1" ) if not data.get("model_name"): data["model_name"] = os.getenv( "MODEL_NAME", "qwen3.7-plus" ) # Load Hugging Face configuration if not data.get("huggingface_token"): data["huggingface_token"] = os.getenv("HUGGINGFACE_TOKEN", "") if not data.get("huggingface_dataset"): data["huggingface_dataset"] = os.getenv( "HUGGINGFACE_DATASET", "factorstudios/Pipeline" ) super().__init__(**data) # Create necessary directories Path(self.data_dir).mkdir(parents=True, exist_ok=True) Path(self.output_dir).mkdir(parents=True, exist_ok=True) Path(self.log_dir).mkdir(parents=True, exist_ok=True) logger.info("Configuration loaded successfully") logger.info(f"Model: {self.model_name}") logger.info(f"Dataset: {self.huggingface_dataset}") logger.info(f"Port: {self.port} (all agents on this single port)") # Load settings settings = Settings()