Spaces:
Running
Running
| """Server configuration for NLProxy | |
| Author: IntelliDeep Labs Team | |
| License: BSL 1.1 | |
| """ | |
| from __future__ import annotations | |
| from typing import Any, Literal | |
| from pydantic import BaseModel, ConfigDict, field_validator | |
| from nlproxy.llm.client import LLMProvider | |
| class Settings(BaseModel): | |
| """Runtime settings loaded from environment variables.""" | |
| model_config = ConfigDict(env_prefix="NLPROXY_", case_sensitive=False) | |
| host: str = "0.0.0.0" | |
| port: int = 8000 | |
| workers: int = 4 | |
| log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO" | |
| redis_url: str = "redis://localhost:6379" | |
| redis_max_connections: int = 50 | |
| redis_socket_timeout: float = 5.0 | |
| enable_semantic_cache: bool = True | |
| cache_similarity_threshold: float = 0.92 | |
| cache_default_ttl: int = 3600 | |
| cache_embedding_dim: int = 384 | |
| default_aggressiveness: float = 0.2 | |
| max_compression_timeout: float = 60.0 | |
| compression_max_retries: int = 3 | |
| default_llm_provider: str = "openai" | |
| default_llm_model: str = "gpt-4" | |
| llm_request_timeout: float = 30.0 | |
| llm_max_retries: int = 3 | |
| enable_llm_fallback: bool = True | |
| min_confidence_threshold: float = 0.6 | |
| max_regeneration_attempts: int = 3 | |
| enable_auto_correction: bool = True | |
| privacy_mode_default: bool = False | |
| enable_metrics: bool = True | |
| metrics_path: str = "/metrics" | |
| enable_tracing: bool = False | |
| trace_sample_rate: float = 0.1 | |
| enable_nli_verification: bool = True | |
| enable_perplexity_check: bool = False | |
| enable_semantic_drift: bool = True | |
| def validate_log_level(cls, value: str) -> str: | |
| allowed = {"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"} | |
| normalized = value.upper().strip() | |
| if normalized not in allowed: | |
| raise ValueError(f"log_level must be one of {sorted(allowed)}") | |
| return normalized | |
| def validate_llm_provider(cls, value: str) -> str: | |
| allowed = {p.value for p in LLMProvider} | |
| normalized = value.lower().strip() | |
| if normalized not in allowed: | |
| raise ValueError( | |
| f"Invalid LLM provider: {value}. Must be one of {sorted(allowed)}" | |
| ) | |
| return normalized | |
| def parse_boolean_flags(cls, value: Any) -> bool: | |
| if isinstance(value, str): | |
| normalized = value.strip().lower() | |
| return normalized in {"1", "true", "yes", "on"} | |
| return bool(value) | |
| settings = Settings() | |