petter2025's picture
Update app/api/deps.py
34ba823 verified
raw
history blame
3.44 kB
import sys
from app.database.session import SessionLocal
from slowapi import Limiter
from slowapi.util import get_remote_address
from app.core.config import settings
# ---------------------------------------------------------------------------
# Local dummy implementations that replace the private engine classes.
# They provide the same interface as the originals but perform no real work.
# ---------------------------------------------------------------------------
class RiskEngine:
def __init__(self, *args, **kwargs):
pass
def calculate_risk(self, *args, **kwargs):
return (0.38, "mock", {"conjugate_mean": 0.38})
def update_outcome(self, *args, **kwargs):
pass
class DecisionEngine:
def __init__(self, *args, **kwargs):
pass
def select_optimal_action(self, *args, **kwargs):
class Result:
best_action = type('Action', (), {'value': 'NO_ACTION'})()
expected_utility = 0.0
alternatives = []
explanation = "mock"
raw_data = {}
return Result()
def compute_risk(self, *args, **kwargs):
return 0.0
class LyapunovStabilityController:
def __init__(self, *args, **kwargs):
pass
class CausalExplainer:
def __init__(self, *args, **kwargs):
pass
class RAGGraphMemory:
def __init__(self, *args, **kwargs):
pass
def has_historical_data(self):
return False
def record_outcome(self, *args, **kwargs):
pass
class ReliabilityEvent:
def __init__(self, component, latency_p99, error_rate, service_mesh="default"):
self.component = component
self.latency_p99 = latency_p99
self.error_rate = error_rate
self.service_mesh = service_mesh
class HealingAction:
NO_ACTION = "NO_ACTION"
RESTART_CONTAINER = "RESTART_CONTAINER"
SCALE_OUT = "SCALE_OUT"
ROLLBACK = "ROLLBACK"
CIRCUIT_BREAKER = "CIRCUIT_BREAKER"
TRAFFIC_SHIFT = "TRAFFIC_SHIFT"
ALERT_TEAM = "ALERT_TEAM"
# ---------------------------------------------------------------------------
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
limiter = Limiter(key_func=get_remote_address, default_limits=[settings.RATE_LIMIT])
# Singletons (now using local dummies)
_risk_engine = None
_decision_engine = None
_stability_controller = None
_causal_explainer = None
_rag_graph = None
def _seed_rag_graph(rag):
# Mock seed – no real data
print("RAG seed skipped (sandbox mode)", file=sys.stderr)
def get_rag_graph():
global _rag_graph
if _rag_graph is None:
_rag_graph = RAGGraphMemory()
_seed_rag_graph(_rag_graph)
return _rag_graph
def get_decision_engine():
global _decision_engine
if _decision_engine is None:
rag = get_rag_graph()
_decision_engine = DecisionEngine(rag_graph=rag)
return _decision_engine
def get_risk_engine():
global _risk_engine
if _risk_engine is None:
_risk_engine = RiskEngine()
return _risk_engine
def get_stability_controller():
global _stability_controller
if _stability_controller is None:
_stability_controller = LyapunovStabilityController()
return _stability_controller
def get_causal_explainer():
global _causal_explainer
if _causal_explainer is None:
_causal_explainer = CausalExplainer()
return _causal_explainer