File size: 3,028 Bytes
2dfc473
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35db168
2dfc473
35db168
 
2dfc473
 
 
 
 
 
 
 
 
 
cc1daf4
2dfc473
 
cc1daf4
 
 
 
 
 
 
 
 
 
2dfc473
 
 
 
 
 
 
 
ba96e16
2dfc473
 
35db168
2dfc473
35db168
2dfc473
 
35db168
2dfc473
 
 
35db168
 
 
 
 
 
 
 
 
2dfc473
 
 
 
 
 
 
 
 
 
 
cc1daf4
2dfc473
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""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()