File size: 3,843 Bytes
240e5bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"""
Configuration management for the Technical Mindmap Generator
Handles all application settings and API key management
"""
import os
from dotenv import load_dotenv
from pydantic import BaseModel, Field
from typing import Optional

# Load environment variables from .env file
load_dotenv()


class Settings(BaseModel):
    """
    Application settings with validation

    Attributes:
        gemini_api_key: Google Gemini API key for AI synthesis
        tavily_api_key: Tavily API key for web search
        google_cloud_project_id: Google Cloud project ID for Knowledge Graph
        max_concurrent_requests: Maximum number of parallel API calls
        cache_enabled: Enable/disable result caching
        debug_mode: Enable debug logging
        max_nodes: Maximum nodes in generated mindmap
        max_depth: Maximum depth of node hierarchy
    """

    # API Keys
    gemini_api_key: str = Field(
        default_factory=lambda: os.getenv("GEMINI_API_KEY", ""),
        description="Gemini API key for AI-powered synthesis"
    )

    tavily_api_key: str = Field(
        default_factory=lambda: os.getenv("TAVILY_API_KEY", ""),
        description="Tavily API key for web search"
    )

    google_cloud_api_key: str = Field(
    default_factory=lambda: os.getenv("GOOGLE_CLOUD_API_KEY", ""),
    description="API key for Google Knowledge Graph REST API"
)


    # Application Settings
    max_concurrent_requests: int = Field(
        default_factory=lambda: int(os.getenv("MAX_CONCURRENT_REQUESTS", "3")),
        ge=1,
        le=10,
        description="Maximum concurrent API requests"
    )

    cache_enabled: bool = Field(
        default_factory=lambda: os.getenv("CACHE_ENABLED", "true").lower() == "true",
        description="Enable result caching"
    )

    debug_mode: bool = Field(
        default_factory=lambda: os.getenv("DEBUG_MODE", "false").lower() == "true",
        description="Enable debug mode"
    )

    # Mindmap Settings
    max_nodes: int = Field(
        default_factory=lambda: int(os.getenv("MAX_NODES", "20")),
        ge=5,
        le=50,
        description="Maximum nodes in mindmap"
    )

    max_depth: int = Field(
        default_factory=lambda: int(os.getenv("MAX_DEPTH", "2")),
        ge=1,
        le=5,
        description="Maximum depth of node hierarchy"
    )

    class Config:
        """Pydantic configuration"""
        env_file = ".env"
        case_sensitive = False

    def validate_api_keys(self) -> tuple[bool, list[str]]:
        """
        Validate that all required API keys are present

        Returns:
            Tuple of (is_valid, missing_keys)
        """
        missing_keys = []

        if not self.gemini_api_key:
            missing_keys.append("GEMINI_API_KEY")

        if not self.tavily_api_key:
            missing_keys.append("TAVILY_API_KEY")

        if not self.google_cloud_api_key:
            missing_keys.append("GOOGLE_CLOUD_API_KEY")

        return (len(missing_keys) == 0, missing_keys)


# Create global settings instance
settings = Settings()


def get_settings() -> Settings:
    """
    Get the global settings instance

    Returns:
        Settings object
    """
    return settings


def display_settings_info():
    """Print current settings (for debugging)"""
    print("=" * 50)
    print("TECHNICAL MINDMAP GENERATOR - SETTINGS")
    print("=" * 50)
    print(f"Max Concurrent Requests: {settings.max_concurrent_requests}")
    print(f"Cache Enabled: {settings.cache_enabled}")
    print(f"Debug Mode: {settings.debug_mode}")
    print(f"Max Nodes: {settings.max_nodes}")
    print(f"Max Depth: {settings.max_depth}")

    is_valid, missing = settings.validate_api_keys()
    if is_valid:
        print("✅ All API keys configured")
    else:
        print(f"❌ Missing API keys: {', '.join(missing)}")
    print("=" * 50)