Tech Stack Advisor - Code Viewer

← Back to File Tree

config.py

Language: python | Path: backend/src/core/config.py | Lines: 74
"""Application configuration using Pydantic settings."""
import os
from typing import Literal
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    """Application settings loaded from environment variables."""

    # Anthropic API
    anthropic_api_key: str

    # Qdrant
    qdrant_url: str
    qdrant_api_key: str

    # Authentication
    jwt_secret: str = "your-secret-key-change-in-production-CHANGE-THIS"

    # Google OAuth
    google_client_id: str = ""
    google_client_secret: str = ""
    google_redirect_uri: str = "http://localhost:8000/auth/google/callback"

    # Application
    environment: Literal["development", "production"] = "development"
    log_level: str = "INFO"
    api_host: str = "0.0.0.0"
    port: int = 8000  # Railway sets PORT env var, falls back to 8000 for local dev

    @property
    def api_port(self) -> int:
        """Get API port, preferring PORT env var (Railway) over default."""
        return self.port

    # Rate Limiting
    rate_limit_demo: str = "50/hour"  # Increased for testing
    rate_limit_authenticated: str = "100/hour"
    daily_query_cap: int = 100

    # Cost Monitoring
    daily_budget_usd: float = 2.00
    alert_email: str = ""

    # Model Configuration
    model_name: str = "claude-3-haiku-20240307"  # Haiku - cost effective for demo
    model_temperature: float = 0.7
    max_tokens: int = 4096  # Haiku max output tokens

    # RAG Configuration
    embedding_model: str = "text-embedding-3-small"
    chunk_size: int = 1000
    chunk_overlap: int = 200
    top_k_results: int = 5

    model_config = SettingsConfigDict(
        env_file=".env",
        env_file_encoding="utf-8",
        env_ignore_empty=True,
        extra="ignore",
        case_sensitive=False,
    )


# Global settings instance
def get_settings() -> Settings:
    """Get settings instance - lazy loaded."""
    import os
    print(f"DEBUG: ANTHROPIC_API_KEY present: {bool(os.getenv('ANTHROPIC_API_KEY'))}")
    print(f"DEBUG: QDRANT_URL present: {bool(os.getenv('QDRANT_URL'))}")
    print(f"DEBUG: QDRANT_API_KEY present: {bool(os.getenv('QDRANT_API_KEY'))}")
    return Settings()  # type: ignore[call-arg]

settings = get_settings()