rwttrter / backend /core /config.py
plexdx's picture
Upload 26 files
64d289f verified
"""
core/config.py β€” Centralized settings via pydantic-settings.
All values read from environment variables (set in HF Spaces secrets).
"""
from enum import Enum
from functools import lru_cache
from pydantic import Field, computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict
class HighlightColor(str, Enum):
GREEN = "green" # Fact-checked, widely corroborated
YELLOW = "yellow" # Breaking / unverified / weak signal
RED = "red" # Debunked, active community note
PURPLE = "purple" # LLM hallucination detected
class Platform(str, Enum):
TWITTER = "twitter"
INSTAGRAM = "instagram"
YOUTUBE = "youtube"
CHATGPT = "chatgpt"
CLAUDE = "claude"
GEMINI = "gemini"
NEWS = "news"
UNKNOWN = "unknown"
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
# LLM API keys
groq_api_key: str = Field(default="", alias="GROQ_API_KEY")
x_bearer_token: str = Field(default="", alias="X_BEARER_TOKEN")
# Infrastructure
qdrant_host: str = Field(default="localhost", alias="QDRANT_HOST")
qdrant_port: int = Field(default=6333, alias="QDRANT_PORT")
memgraph_host: str = Field(default="localhost", alias="MEMGRAPH_HOST")
memgraph_port: int = Field(default=7687, alias="MEMGRAPH_PORT")
memgraph_password: str = Field(default="memgraph123", alias="MEMGRAPH_PASSWORD")
redpanda_brokers: str = Field(default="localhost:9092", alias="REDPANDA_BROKERS")
redis_url: str = Field(default="redis://localhost:6379", alias="REDIS_URL")
# App
port: int = Field(default=7860, alias="PORT")
log_level: str = Field(default="INFO", alias="LOG_LEVEL")
demo_mode: bool = Field(default=False, alias="DEMO_MODE")
# Model identifiers for LiteLLM routing
gatekeeper_model: str = "groq/llama3-8b-8192"
misinformation_model: str = "groq/mixtral-8x7b-32768"
hallucination_model: str = "groq/llama3-70b-8192" # Free via Groq β€” replaces Claude Haiku
# Gatekeeper latency SLO: p95 < 120ms
gatekeeper_timeout_ms: int = 120
# Cache TTLs (seconds)
cache_ttl_green_red: int = 21_600 # 6 hours
cache_ttl_yellow: int = 900 # 15 minutes
# Purple: no cache β€” hallucination checks are context-specific
# RAG retrieval
qdrant_collection: str = "claims"
qdrant_ef: int = 128 # HNSW ef parameter β€” higher = more accurate, slower
qdrant_top_k: int = 8 # nearest neighbors to retrieve
evidence_window_hours: int = 72 # only retrieve evidence newer than 72h
# Minimum text length for analysis (words)
min_word_count: int = 12
@computed_field
@property
def has_groq(self) -> bool:
return bool(self.groq_api_key)
@computed_field
@property
def has_hallucination_llm(self) -> bool:
# Hallucination agent uses Groq llama3-70b (free) β€” same key as gatekeeper
return bool(self.groq_api_key)
@computed_field
@property
def has_x_api(self) -> bool:
return bool(self.x_bearer_token)
@computed_field
@property
def broker_list(self) -> list[str]:
return self.redpanda_brokers.split(",")
@lru_cache
def get_settings() -> Settings:
return Settings()