File size: 2,174 Bytes
4780a80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from pydantic_settings import BaseSettings
from typing import Dict, Any

class Settings(BaseSettings):
    # API Keys
    API_KEY: str = os.getenv("API_KEY", "your_default_api_key")
    OPENAI_API_KEY: str = os.getenv("OPENAI_API_KEY", "")
    GROQ_API_TOKEN: str = os.getenv("GROQ_API_KEY", "")

    
    # Server Configuration
    API_PREFIX: str = "/api"
    RATE_LIMIT_PER_MINUTE: int = 10
    
    # Model Configuration
    ENGLISH_MODEL: str = "google/flan-t5-base"
    HINDI_MODEL: str = "google/mt5-base"
    HINGLISH_MODEL: str = "google/mt5-base"
    MAX_NEW_TOKENS: int = 256
    
    # Gradio Configuration
    GRADIO_SERVER_NAME: str = os.getenv("GRADIO_SERVER_NAME", "0.0.0.0")
    GRADIO_SERVER_PORT: int = int(os.getenv("GRADIO_SERVER_PORT", "7860"))
    GRADIO_SHARE: bool = os.getenv("GRADIO_SHARE", "True").lower() == "true"
    
    # Storage Configuration
    LOG_FILE: str = os.getenv("LOG_FILE", "logs/specter.log")
    LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO")
    PDF_STORAGE_PATH: str = os.getenv("PDF_STORAGE_PATH", "storage/pdfs")
    MAX_PDF_AGE_DAYS: int = int(os.getenv("MAX_PDF_AGE_DAYS", "7"))
    LEGAL_DOCS_PATH: str = os.getenv("LEGAL_DOCS_PATH", "data/legal_docs")
    VECTOR_STORE_PATH: str = os.getenv("VECTOR_STORE_PATH", "data/vector_store")
    
    # Public URL for audio files
    PUBLIC_BASE_URL: str = os.getenv("PUBLIC_BASE_URL", "http://localhost:8001")

    model_config = {
        "env_file": ".env",
        "extra": "ignore"
    }

settings = Settings()

# Validate critical settings
def validate_settings():
    """Validate critical settings and warn about missing configurations."""
    warnings = []
    
    if settings.API_KEY == "your_default_api_key":
        warnings.append("API_KEY is using default value - set API_KEY environment variable")
    
    if not settings.GROQ_API_TOKEN:
        warnings.append("GROQ_API_TOKEN is not set - AI responses will not work")
    
    if warnings:
        print("⚠️  Configuration Warnings:")
        for warning in warnings:
            print(f"   - {warning}")
    else:
        print("✅ Configuration validated successfully")

validate_settings()