Spaces:
Sleeping
Sleeping
Bug fixes
Browse files- pyproject.toml +17 -9
- requirements.txt +2 -21
- src/adaptive_alert_triage/__init__.py +2 -2
- src/adaptive_alert_triage/env.py +9 -8
- src/adaptive_alert_triage/models.py +1 -1
- src/adaptive_alert_triage/utils.py +1 -1
- test_endpoints.py +41 -0
pyproject.toml
CHANGED
|
@@ -27,25 +27,30 @@ classifiers = [
|
|
| 27 |
|
| 28 |
dependencies = [
|
| 29 |
"pydantic>=2.0.0",
|
| 30 |
-
"openenv>=0.1.0",
|
| 31 |
"numpy>=1.24.0",
|
| 32 |
"openai>=1.0.0",
|
| 33 |
-
"typer>=0.9.0",
|
| 34 |
"pyyaml>=6.0",
|
| 35 |
-
"matplotlib>=3.7.0",
|
| 36 |
-
"pandas>=2.0.0",
|
| 37 |
-
"google-genai>=0.8.0",
|
| 38 |
"uvicorn[standard]>=0.24.0",
|
| 39 |
"fastapi>=0.104.0",
|
| 40 |
-
"seaborn>=0.12.0",
|
| 41 |
"websockets>=12.0",
|
| 42 |
-
"stable-baselines3>=2.0.0",
|
| 43 |
"requests>=2.31.0",
|
| 44 |
-
"pytest>=7.4.0",
|
| 45 |
-
"pytest-cov>=4.1.0",
|
| 46 |
]
|
| 47 |
|
| 48 |
[project.optional-dependencies]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
dev = [
|
| 50 |
"pytest>=7.4.0",
|
| 51 |
"pytest-cov>=4.1.0",
|
|
@@ -53,6 +58,9 @@ dev = [
|
|
| 53 |
"ruff>=0.0.280",
|
| 54 |
"mypy>=1.4.0",
|
| 55 |
]
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
[project.urls]
|
| 58 |
Homepage = "https://github.com/scalar/adaptive-alert-triage"
|
|
|
|
| 27 |
|
| 28 |
dependencies = [
|
| 29 |
"pydantic>=2.0.0",
|
|
|
|
| 30 |
"numpy>=1.24.0",
|
| 31 |
"openai>=1.0.0",
|
|
|
|
| 32 |
"pyyaml>=6.0",
|
|
|
|
|
|
|
|
|
|
| 33 |
"uvicorn[standard]>=0.24.0",
|
| 34 |
"fastapi>=0.104.0",
|
|
|
|
| 35 |
"websockets>=12.0",
|
|
|
|
| 36 |
"requests>=2.31.0",
|
|
|
|
|
|
|
| 37 |
]
|
| 38 |
|
| 39 |
[project.optional-dependencies]
|
| 40 |
+
train = [
|
| 41 |
+
"stable-baselines3>=2.0.0",
|
| 42 |
+
]
|
| 43 |
+
viz = [
|
| 44 |
+
"matplotlib>=3.7.0",
|
| 45 |
+
"pandas>=2.0.0",
|
| 46 |
+
"seaborn>=0.12.0",
|
| 47 |
+
]
|
| 48 |
+
gemini = [
|
| 49 |
+
"google-genai>=0.8.0",
|
| 50 |
+
]
|
| 51 |
+
cli = [
|
| 52 |
+
"typer>=0.9.0",
|
| 53 |
+
]
|
| 54 |
dev = [
|
| 55 |
"pytest>=7.4.0",
|
| 56 |
"pytest-cov>=4.1.0",
|
|
|
|
| 58 |
"ruff>=0.0.280",
|
| 59 |
"mypy>=1.4.0",
|
| 60 |
]
|
| 61 |
+
all = [
|
| 62 |
+
"adaptive-alert-triage[train,viz,gemini,cli,dev]",
|
| 63 |
+
]
|
| 64 |
|
| 65 |
[project.urls]
|
| 66 |
Homepage = "https://github.com/scalar/adaptive-alert-triage"
|
requirements.txt
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
# requirements.txt — Adaptive Alert Triage
|
| 2 |
-
#
|
| 3 |
# Designed for 2 vCPU / 8 GB RAM (HF Spaces free tier)
|
| 4 |
# No PyTorch / TensorFlow — RL agent is pure numpy
|
| 5 |
|
| 6 |
# ── Core environment ──────────────────────────────────────────────────────────
|
| 7 |
-
openenv>=0.1.0
|
| 8 |
numpy>=1.24.0
|
| 9 |
pydantic>=2.0.0
|
| 10 |
|
|
@@ -16,26 +15,8 @@ websockets>=12.0
|
|
| 16 |
# ── LLM inference (OpenAI client — required by checklist) ────────────────────
|
| 17 |
openai>=1.0.0
|
| 18 |
|
| 19 |
-
# ── Gemini SDK (legacy inference.py in agents/ still uses it) ────────────────
|
| 20 |
-
google-genai>=0.8.0
|
| 21 |
-
|
| 22 |
# ── HTTP client (train_external.py, real-alert listener) ─────────────────────
|
| 23 |
requests>=2.31.0
|
| 24 |
|
| 25 |
-
# ── Data / plotting ───────────────────────────────────────────────────────────
|
| 26 |
-
matplotlib>=3.7.0
|
| 27 |
-
pandas>=2.0.0
|
| 28 |
-
seaborn>=0.12.0
|
| 29 |
-
|
| 30 |
# ── YAML parsing ─────────────────────────────────────────────────────────────
|
| 31 |
-
pyyaml>=6.0
|
| 32 |
-
|
| 33 |
-
# ── CLI helpers ───────────────────────────────────────────────────────────────
|
| 34 |
-
typer>=0.9.0
|
| 35 |
-
|
| 36 |
-
# ── Testing ───────────────────────────────────────────────────────────────────
|
| 37 |
-
pytest>=7.4.0
|
| 38 |
-
pytest-cov>=4.1.0
|
| 39 |
-
|
| 40 |
-
# ── External RL trainer (optional — not needed for server or inference) ────────
|
| 41 |
-
# stable-baselines3>=2.0.0 # uncomment if using train_external.py
|
|
|
|
| 1 |
# requirements.txt — Adaptive Alert Triage
|
| 2 |
+
# Server-only dependencies (matches pyproject.toml core deps)
|
| 3 |
# Designed for 2 vCPU / 8 GB RAM (HF Spaces free tier)
|
| 4 |
# No PyTorch / TensorFlow — RL agent is pure numpy
|
| 5 |
|
| 6 |
# ── Core environment ──────────────────────────────────────────────────────────
|
|
|
|
| 7 |
numpy>=1.24.0
|
| 8 |
pydantic>=2.0.0
|
| 9 |
|
|
|
|
| 15 |
# ── LLM inference (OpenAI client — required by checklist) ────────────────────
|
| 16 |
openai>=1.0.0
|
| 17 |
|
|
|
|
|
|
|
|
|
|
| 18 |
# ── HTTP client (train_external.py, real-alert listener) ─────────────────────
|
| 19 |
requests>=2.31.0
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# ── YAML parsing ─────────────────────────────────────────────────────────────
|
| 22 |
+
pyyaml>=6.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/adaptive_alert_triage/__init__.py
CHANGED
|
@@ -8,8 +8,8 @@ for alert triage and incident response simulation.
|
|
| 8 |
__version__ = "0.1.0"
|
| 9 |
__author__ = "Scalar Hackathon Team"
|
| 10 |
|
| 11 |
-
from
|
| 12 |
-
from
|
| 13 |
|
| 14 |
__all__ = [
|
| 15 |
"AdaptiveAlertTriageEnv",
|
|
|
|
| 8 |
__version__ = "0.1.0"
|
| 9 |
__author__ = "Scalar Hackathon Team"
|
| 10 |
|
| 11 |
+
from .env import AdaptiveAlertTriageEnv
|
| 12 |
+
from .models import Action, Observation, Reward, Alert
|
| 13 |
|
| 14 |
__all__ = [
|
| 15 |
"AdaptiveAlertTriageEnv",
|
src/adaptive_alert_triage/env.py
CHANGED
|
@@ -46,26 +46,27 @@ import numpy as np
|
|
| 46 |
import openenv as gym
|
| 47 |
from openenv import spaces
|
| 48 |
|
| 49 |
-
from
|
| 50 |
Action,
|
| 51 |
Alert,
|
| 52 |
EpisodeState,
|
| 53 |
Observation,
|
| 54 |
Reward,
|
| 55 |
)
|
| 56 |
-
from
|
| 57 |
|
| 58 |
# Import reward calculation with graceful fallback for development mode
|
|
|
|
|
|
|
|
|
|
| 59 |
try:
|
| 60 |
from rewards.reward import calculate_reward
|
| 61 |
except ImportError:
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
_project_root = os.path.dirname(
|
| 66 |
-
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 67 |
)
|
| 68 |
-
|
|
|
|
| 69 |
from rewards.reward import calculate_reward # type: ignore[no-redef]
|
| 70 |
|
| 71 |
|
|
|
|
| 46 |
import openenv as gym
|
| 47 |
from openenv import spaces
|
| 48 |
|
| 49 |
+
from .models import (
|
| 50 |
Action,
|
| 51 |
Alert,
|
| 52 |
EpisodeState,
|
| 53 |
Observation,
|
| 54 |
Reward,
|
| 55 |
)
|
| 56 |
+
from . import utils
|
| 57 |
|
| 58 |
# Import reward calculation with graceful fallback for development mode
|
| 59 |
+
import os as _os
|
| 60 |
+
import sys as _sys
|
| 61 |
+
|
| 62 |
try:
|
| 63 |
from rewards.reward import calculate_reward
|
| 64 |
except ImportError:
|
| 65 |
+
_project_root = _os.path.dirname(
|
| 66 |
+
_os.path.dirname(_os.path.dirname(_os.path.abspath(__file__)))
|
|
|
|
|
|
|
|
|
|
| 67 |
)
|
| 68 |
+
if _project_root not in _sys.path:
|
| 69 |
+
_sys.path.insert(0, _project_root)
|
| 70 |
from rewards.reward import calculate_reward # type: ignore[no-redef]
|
| 71 |
|
| 72 |
|
src/adaptive_alert_triage/models.py
CHANGED
|
@@ -289,7 +289,7 @@ class EpisodeState(BaseModel):
|
|
| 289 |
failures_count: int = Field(
|
| 290 |
default=0, ge=0, description="System failures so far"
|
| 291 |
)
|
| 292 |
-
actions_taken: List[
|
| 293 |
default_factory=list, description="Full action history for this episode"
|
| 294 |
)
|
| 295 |
seed: Optional[int] = Field(
|
|
|
|
| 289 |
failures_count: int = Field(
|
| 290 |
default=0, ge=0, description="System failures so far"
|
| 291 |
)
|
| 292 |
+
actions_taken: List[Dict[str, Any]] = Field(
|
| 293 |
default_factory=list, description="Full action history for this episode"
|
| 294 |
)
|
| 295 |
seed: Optional[int] = Field(
|
src/adaptive_alert_triage/utils.py
CHANGED
|
@@ -17,7 +17,7 @@ from typing import List, Dict, Tuple, Optional
|
|
| 17 |
|
| 18 |
import numpy as np
|
| 19 |
|
| 20 |
-
from
|
| 21 |
|
| 22 |
|
| 23 |
# ---------------------------------------------------------------------------
|
|
|
|
| 17 |
|
| 18 |
import numpy as np
|
| 19 |
|
| 20 |
+
from .models import Alert, AlertType
|
| 21 |
|
| 22 |
|
| 23 |
# ---------------------------------------------------------------------------
|
test_endpoints.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test script to verify endpoints are accessible.
|
| 4 |
+
Usage: python test_endpoints.py https://tusharp2006-scaler_deployment.hf.space
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
import httpx
|
| 9 |
+
|
| 10 |
+
async def test_endpoints(base_url: str):
|
| 11 |
+
"""Test all key endpoints"""
|
| 12 |
+
endpoints = [
|
| 13 |
+
"/",
|
| 14 |
+
"/health",
|
| 15 |
+
"/metrics",
|
| 16 |
+
"/tasks",
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
base_url = base_url.rstrip("/")
|
| 20 |
+
|
| 21 |
+
async with httpx.AsyncClient(timeout=10.0) as client:
|
| 22 |
+
for endpoint in endpoints:
|
| 23 |
+
url = f"{base_url}{endpoint}"
|
| 24 |
+
try:
|
| 25 |
+
resp = await client.get(url)
|
| 26 |
+
print(f"[{resp.status_code}] GET {endpoint}")
|
| 27 |
+
if resp.status_code < 300:
|
| 28 |
+
print(f" ✓ Response: {str(resp.json())[:100]}")
|
| 29 |
+
else:
|
| 30 |
+
print(f" ✗ Error: {resp.text[:100]}")
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"[ERROR] GET {endpoint} - {e}")
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
import asyncio
|
| 36 |
+
if len(sys.argv) < 2:
|
| 37 |
+
print("Usage: python test_endpoints.py <base_url>")
|
| 38 |
+
print("Example: python test_endpoints.py https://tusharp2006-scaler_deployment.hf.space")
|
| 39 |
+
sys.exit(1)
|
| 40 |
+
|
| 41 |
+
asyncio.run(test_endpoints(sys.argv[1]))
|