Update config/settings.py
Browse files- config/settings.py +182 -12
config/settings.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
"""
|
| 2 |
Configuration management for ARF Demo
|
| 3 |
-
Updated
|
| 4 |
"""
|
| 5 |
from typing import Optional, Dict, Any, List
|
| 6 |
from enum import Enum
|
| 7 |
import os
|
| 8 |
import logging
|
|
|
|
| 9 |
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
|
|
@@ -55,6 +56,14 @@ class SafetyMode(str, Enum):
|
|
| 55 |
AUTONOMOUS = "autonomous"
|
| 56 |
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
class Settings(BaseSettings):
|
| 59 |
"""
|
| 60 |
Application settings with environment variable support
|
|
@@ -66,9 +75,30 @@ class Settings(BaseSettings):
|
|
| 66 |
description="ARF operation mode"
|
| 67 |
)
|
| 68 |
|
| 69 |
-
|
| 70 |
default=True,
|
| 71 |
-
description="Use
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
)
|
| 73 |
|
| 74 |
# ===== ARF Configuration =====
|
|
@@ -138,12 +168,104 @@ class Settings(BaseSettings):
|
|
| 138 |
raise ValueError("ARF API key required for Enterprise mode")
|
| 139 |
return v
|
| 140 |
|
| 141 |
-
@validator("
|
| 142 |
-
def
|
| 143 |
-
if values.get("
|
| 144 |
-
|
|
|
|
| 145 |
return v
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
class Config:
|
| 148 |
env_file = ".env"
|
| 149 |
env_file_encoding = "utf-8"
|
|
@@ -151,14 +273,34 @@ class Settings(BaseSettings):
|
|
| 151 |
use_enum_values = True
|
| 152 |
|
| 153 |
|
| 154 |
-
# Global settings instance with
|
| 155 |
try:
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
except Exception as e:
|
| 158 |
-
logger.warning(f"Failed to load settings
|
| 159 |
settings = Settings(
|
| 160 |
arf_mode=ARFMode.DEMO,
|
| 161 |
-
|
|
|
|
|
|
|
| 162 |
engineer_hourly_rate=150.0,
|
| 163 |
engineer_annual_cost=125000.0,
|
| 164 |
default_savings_rate=0.82,
|
|
@@ -173,4 +315,32 @@ except Exception as e:
|
|
| 173 |
|
| 174 |
def get_settings() -> Settings:
|
| 175 |
"""Get settings instance (singleton pattern)"""
|
| 176 |
-
return settings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""
|
| 2 |
Configuration management for ARF Demo
|
| 3 |
+
Updated with REAL ARF installation detection
|
| 4 |
"""
|
| 5 |
from typing import Optional, Dict, Any, List
|
| 6 |
from enum import Enum
|
| 7 |
import os
|
| 8 |
import logging
|
| 9 |
+
import sys
|
| 10 |
|
| 11 |
logger = logging.getLogger(__name__)
|
| 12 |
|
|
|
|
| 56 |
AUTONOMOUS = "autonomous"
|
| 57 |
|
| 58 |
|
| 59 |
+
class InstallationStatus(str, Enum):
|
| 60 |
+
"""ARF package installation status"""
|
| 61 |
+
NOT_INSTALLED = "not_installed"
|
| 62 |
+
OSS_ONLY = "oss_only"
|
| 63 |
+
ENTERPRISE = "enterprise"
|
| 64 |
+
BOTH = "both"
|
| 65 |
+
|
| 66 |
+
|
| 67 |
class Settings(BaseSettings):
|
| 68 |
"""
|
| 69 |
Application settings with environment variable support
|
|
|
|
| 75 |
description="ARF operation mode"
|
| 76 |
)
|
| 77 |
|
| 78 |
+
use_true_arf: bool = Field(
|
| 79 |
default=True,
|
| 80 |
+
description="Use true ARF integration when available"
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# ===== Installation Status (Auto-detected) =====
|
| 84 |
+
arf_oss_installed: bool = Field(
|
| 85 |
+
default=False,
|
| 86 |
+
description="ARF OSS package installed"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
arf_enterprise_installed: bool = Field(
|
| 90 |
+
default=False,
|
| 91 |
+
description="ARF Enterprise package installed"
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
arf_oss_version: Optional[str] = Field(
|
| 95 |
+
default=None,
|
| 96 |
+
description="ARF OSS version if installed"
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
arf_enterprise_version: Optional[str] = Field(
|
| 100 |
+
default=None,
|
| 101 |
+
description="ARF Enterprise version if installed"
|
| 102 |
)
|
| 103 |
|
| 104 |
# ===== ARF Configuration =====
|
|
|
|
| 168 |
raise ValueError("ARF API key required for Enterprise mode")
|
| 169 |
return v
|
| 170 |
|
| 171 |
+
@validator("use_true_arf")
|
| 172 |
+
def validate_true_arf(cls, v: bool, values: Dict[str, Any]) -> bool:
|
| 173 |
+
if v and not values.get("arf_oss_installed"):
|
| 174 |
+
logger.warning("True ARF requested but OSS package not installed. Using mock mode.")
|
| 175 |
+
return False
|
| 176 |
return v
|
| 177 |
|
| 178 |
+
# ===== Installation Detection =====
|
| 179 |
+
@classmethod
|
| 180 |
+
def detect_installation(cls):
|
| 181 |
+
"""Detect ARF package installation"""
|
| 182 |
+
results = {
|
| 183 |
+
"oss_installed": False,
|
| 184 |
+
"enterprise_installed": False,
|
| 185 |
+
"oss_version": None,
|
| 186 |
+
"enterprise_version": None
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
# Check OSS package
|
| 190 |
+
try:
|
| 191 |
+
import agentic_reliability_framework as arf_oss
|
| 192 |
+
results["oss_installed"] = True
|
| 193 |
+
results["oss_version"] = getattr(arf_oss, '__version__', '3.3.7')
|
| 194 |
+
logger.info(f"β
ARF OSS v{results['oss_version']} detected")
|
| 195 |
+
except ImportError:
|
| 196 |
+
logger.info("β οΈ ARF OSS not installed - will use mock mode")
|
| 197 |
+
|
| 198 |
+
# Check Enterprise package
|
| 199 |
+
try:
|
| 200 |
+
import arf_enterprise
|
| 201 |
+
results["enterprise_installed"] = True
|
| 202 |
+
results["enterprise_version"] = getattr(arf_enterprise, '__version__', '1.0.2')
|
| 203 |
+
logger.info(f"β
ARF Enterprise v{results['enterprise_version']} detected")
|
| 204 |
+
except ImportError:
|
| 205 |
+
logger.info("β οΈ ARF Enterprise not installed - will use simulation")
|
| 206 |
+
|
| 207 |
+
return results
|
| 208 |
+
|
| 209 |
+
def get_installation_status(self) -> InstallationStatus:
|
| 210 |
+
"""Get current installation status"""
|
| 211 |
+
if self.arf_oss_installed and self.arf_enterprise_installed:
|
| 212 |
+
return InstallationStatus.BOTH
|
| 213 |
+
elif self.arf_enterprise_installed:
|
| 214 |
+
return InstallationStatus.ENTERPRISE
|
| 215 |
+
elif self.arf_oss_installed:
|
| 216 |
+
return InstallationStatus.OSS_ONLY
|
| 217 |
+
else:
|
| 218 |
+
return InstallationStatus.NOT_INSTALLED
|
| 219 |
+
|
| 220 |
+
def get_installation_badges(self) -> Dict[str, Any]:
|
| 221 |
+
"""Get badge information for UI display"""
|
| 222 |
+
if self.arf_oss_installed:
|
| 223 |
+
oss_badge = {
|
| 224 |
+
"text": f"β
ARF OSS v{self.arf_oss_version}",
|
| 225 |
+
"color": "#10b981",
|
| 226 |
+
"icon": "β
"
|
| 227 |
+
}
|
| 228 |
+
else:
|
| 229 |
+
oss_badge = {
|
| 230 |
+
"text": "β οΈ Mock ARF",
|
| 231 |
+
"color": "#f59e0b",
|
| 232 |
+
"icon": "β οΈ"
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
if self.arf_enterprise_installed:
|
| 236 |
+
enterprise_badge = {
|
| 237 |
+
"text": f"π Enterprise v{self.arf_enterprise_version}",
|
| 238 |
+
"color": "#8b5cf6",
|
| 239 |
+
"icon": "π"
|
| 240 |
+
}
|
| 241 |
+
else:
|
| 242 |
+
enterprise_badge = {
|
| 243 |
+
"text": "π Enterprise Required",
|
| 244 |
+
"color": "#64748b",
|
| 245 |
+
"icon": "π"
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
return {
|
| 249 |
+
"oss": oss_badge,
|
| 250 |
+
"enterprise": enterprise_badge
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
def get_installation_recommendations(self) -> List[str]:
|
| 254 |
+
"""Get installation recommendations"""
|
| 255 |
+
recommendations = []
|
| 256 |
+
|
| 257 |
+
if not self.arf_oss_installed:
|
| 258 |
+
recommendations.append(
|
| 259 |
+
"Install real ARF OSS: `pip install agentic-reliability-framework==3.3.7`"
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
if not self.arf_enterprise_installed:
|
| 263 |
+
recommendations.append(
|
| 264 |
+
"Install ARF Enterprise: `pip install agentic-reliability-enterprise` (requires license)"
|
| 265 |
+
)
|
| 266 |
+
|
| 267 |
+
return recommendations
|
| 268 |
+
|
| 269 |
class Config:
|
| 270 |
env_file = ".env"
|
| 271 |
env_file_encoding = "utf-8"
|
|
|
|
| 273 |
use_enum_values = True
|
| 274 |
|
| 275 |
|
| 276 |
+
# Global settings instance with installation detection
|
| 277 |
try:
|
| 278 |
+
# First detect installation
|
| 279 |
+
installation_info = Settings.detect_installation()
|
| 280 |
+
|
| 281 |
+
# Create settings with installation info
|
| 282 |
+
settings = Settings(
|
| 283 |
+
arf_oss_installed=installation_info["oss_installed"],
|
| 284 |
+
arf_enterprise_installed=installation_info["enterprise_installed"],
|
| 285 |
+
arf_oss_version=installation_info["oss_version"],
|
| 286 |
+
arf_enterprise_version=installation_info["enterprise_version"],
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
# Log installation status
|
| 290 |
+
status = settings.get_installation_status()
|
| 291 |
+
logger.info(f"ARF Installation Status: {status.value}")
|
| 292 |
+
|
| 293 |
+
if status == InstallationStatus.NOT_INSTALLED:
|
| 294 |
+
logger.warning("No ARF packages installed. Demo will use mock mode.")
|
| 295 |
+
logger.warning("For real ARF experience, install: pip install agentic-reliability-framework==3.3.7")
|
| 296 |
+
|
| 297 |
except Exception as e:
|
| 298 |
+
logger.warning(f"Failed to load settings: {e}, using defaults")
|
| 299 |
settings = Settings(
|
| 300 |
arf_mode=ARFMode.DEMO,
|
| 301 |
+
use_true_arf=False,
|
| 302 |
+
arf_oss_installed=False,
|
| 303 |
+
arf_enterprise_installed=False,
|
| 304 |
engineer_hourly_rate=150.0,
|
| 305 |
engineer_annual_cost=125000.0,
|
| 306 |
default_savings_rate=0.82,
|
|
|
|
| 315 |
|
| 316 |
def get_settings() -> Settings:
|
| 317 |
"""Get settings instance (singleton pattern)"""
|
| 318 |
+
return settings
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
def print_installation_status():
|
| 322 |
+
"""Print installation status to console"""
|
| 323 |
+
s = get_settings()
|
| 324 |
+
status = s.get_installation_status()
|
| 325 |
+
|
| 326 |
+
print("=" * 70)
|
| 327 |
+
print("π ARF Ultimate Investor Demo - Installation Status")
|
| 328 |
+
print("=" * 70)
|
| 329 |
+
|
| 330 |
+
print(f"π¦ ARF OSS: {'β
v' + s.arf_oss_version if s.arf_oss_installed else 'β οΈ Not installed'}")
|
| 331 |
+
print(f"π’ Enterprise: {'β
v' + s.arf_enterprise_version if s.arf_enterprise_installed else 'β οΈ Not installed'}")
|
| 332 |
+
print(f"π― Mode: {s.arf_mode.value}")
|
| 333 |
+
print(f"π€ Using True ARF: {'β
Yes' if s.use_true_arf else 'β οΈ Mock mode'}")
|
| 334 |
+
|
| 335 |
+
recommendations = s.get_installation_recommendations()
|
| 336 |
+
if recommendations:
|
| 337 |
+
print("\nπ‘ Recommendations:")
|
| 338 |
+
for rec in recommendations:
|
| 339 |
+
print(f" β’ {rec}")
|
| 340 |
+
|
| 341 |
+
print("=" * 70)
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
# Print status on import (but only if not in test mode)
|
| 345 |
+
if __name__ != "__main__" and "pytest" not in sys.modules:
|
| 346 |
+
print_installation_status()
|