| """ |
| 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_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 |
| """ |
|
|
| |
| 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" |
| ) |
|
|
|
|
| |
| 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" |
| ) |
|
|
| |
| 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) |
|
|
|
|
| |
| 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) |
|
|