Create config.py
Browse files
config.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Configuration management for Agentic Reliability Framework
|
| 3 |
+
|
| 4 |
+
Loads settings from environment variables with sensible defaults.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from typing import Optional
|
| 10 |
+
from dotenv import load_dotenv
|
| 11 |
+
|
| 12 |
+
# Load .env file if it exists
|
| 13 |
+
load_dotenv()
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@dataclass
|
| 17 |
+
class AppConfig:
|
| 18 |
+
"""Application configuration from environment variables"""
|
| 19 |
+
|
| 20 |
+
# API Configuration
|
| 21 |
+
hf_api_key: str = os.getenv("HF_API_KEY", "")
|
| 22 |
+
hf_api_url: str = os.getenv(
|
| 23 |
+
"HF_API_URL",
|
| 24 |
+
"https://router.huggingface.co/hf-inference/v1/completions"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# System Configuration
|
| 28 |
+
max_events_stored: int = int(os.getenv("MAX_EVENTS_STORED", "1000"))
|
| 29 |
+
faiss_batch_size: int = int(os.getenv("FAISS_BATCH_SIZE", "10"))
|
| 30 |
+
faiss_save_interval: int = int(os.getenv("FAISS_SAVE_INTERVAL_SECONDS", "30"))
|
| 31 |
+
vector_dim: int = int(os.getenv("VECTOR_DIM", "384"))
|
| 32 |
+
|
| 33 |
+
# Business Metrics
|
| 34 |
+
base_revenue_per_minute: float = float(os.getenv("BASE_REVENUE_PER_MINUTE", "100.0"))
|
| 35 |
+
base_users: int = int(os.getenv("BASE_USERS", "1000"))
|
| 36 |
+
|
| 37 |
+
# Rate Limiting
|
| 38 |
+
max_requests_per_minute: int = int(os.getenv("MAX_REQUESTS_PER_MINUTE", "60"))
|
| 39 |
+
max_requests_per_hour: int = int(os.getenv("MAX_REQUESTS_PER_HOUR", "500"))
|
| 40 |
+
|
| 41 |
+
# Logging
|
| 42 |
+
log_level: str = os.getenv("LOG_LEVEL", "INFO")
|
| 43 |
+
|
| 44 |
+
# Thresholds
|
| 45 |
+
latency_warning: float = float(os.getenv("LATENCY_WARNING", "150.0"))
|
| 46 |
+
latency_critical: float = float(os.getenv("LATENCY_CRITICAL", "300.0"))
|
| 47 |
+
latency_extreme: float = float(os.getenv("LATENCY_EXTREME", "500.0"))
|
| 48 |
+
|
| 49 |
+
@classmethod
|
| 50 |
+
def from_env(cls) -> "AppConfig":
|
| 51 |
+
"""Create configuration from environment variables"""
|
| 52 |
+
return cls()
|
| 53 |
+
|
| 54 |
+
def validate(self) -> bool:
|
| 55 |
+
"""Validate configuration"""
|
| 56 |
+
if self.vector_dim <= 0:
|
| 57 |
+
raise ValueError("VECTOR_DIM must be positive")
|
| 58 |
+
if self.max_events_stored <= 0:
|
| 59 |
+
raise ValueError("MAX_EVENTS_STORED must be positive")
|
| 60 |
+
return True
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
# Global config instance
|
| 64 |
+
config = AppConfig.from_env()
|
| 65 |
+
config.validate()
|