Spaces:
Sleeping
Sleeping
Fix: update tasks/rate_limit/grader.py
Browse files- tasks/rate_limit/grader.py +13 -23
tasks/rate_limit/grader.py
CHANGED
|
@@ -1,23 +1,18 @@
|
|
| 1 |
"""Grader for rate_limit task: 429 Too Many Requests."""
|
| 2 |
|
| 3 |
-
import sys
|
| 4 |
-
from pathlib import Path
|
| 5 |
-
|
| 6 |
-
_project_root = str(Path(__file__).parent.parent.parent)
|
| 7 |
-
if _project_root not in sys.path:
|
| 8 |
-
sys.path.insert(0, _project_root)
|
| 9 |
-
|
| 10 |
-
from environment.api_triage_env import APITriageEnv
|
| 11 |
-
from environment.incident_generator import get_incident_by_type
|
| 12 |
-
|
| 13 |
|
| 14 |
def grade() -> float:
|
| 15 |
-
"""Grade the rate_limit task
|
| 16 |
-
|
| 17 |
-
Returns:
|
| 18 |
-
Score strictly between 0 and 1.
|
| 19 |
-
"""
|
| 20 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
env = APITriageEnv(max_steps=10)
|
| 22 |
env.incident = get_incident_by_type("rate_limit")
|
| 23 |
if env.incident is None:
|
|
@@ -27,15 +22,10 @@ def grade() -> float:
|
|
| 27 |
env.step_counter = 0
|
| 28 |
env.total_reward = 0.0
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
for action in actions:
|
| 33 |
-
state, reward, done, info = env.step(action)
|
| 34 |
if done:
|
| 35 |
-
if info.get("resolution") == "success"
|
| 36 |
-
return 0.95
|
| 37 |
-
else:
|
| 38 |
-
return 0.1
|
| 39 |
return 0.1
|
| 40 |
except Exception:
|
| 41 |
return 0.1
|
|
|
|
| 1 |
"""Grader for rate_limit task: 429 Too Many Requests."""
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def grade() -> float:
|
| 5 |
+
"""Grade the rate_limit task. Returns float strictly between 0 and 1."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
try:
|
| 7 |
+
import sys
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
_root = str(Path(__file__).resolve().parent.parent.parent)
|
| 10 |
+
if _root not in sys.path:
|
| 11 |
+
sys.path.insert(0, _root)
|
| 12 |
+
|
| 13 |
+
from environment.api_triage_env import APITriageEnv
|
| 14 |
+
from environment.incident_generator import get_incident_by_type
|
| 15 |
+
|
| 16 |
env = APITriageEnv(max_steps=10)
|
| 17 |
env.incident = get_incident_by_type("rate_limit")
|
| 18 |
if env.incident is None:
|
|
|
|
| 22 |
env.step_counter = 0
|
| 23 |
env.total_reward = 0.0
|
| 24 |
|
| 25 |
+
for action in ["inspect_logs", "wait_retry", "resolve"]:
|
| 26 |
+
_, _, done, info = env.step(action)
|
|
|
|
|
|
|
| 27 |
if done:
|
| 28 |
+
return 0.95 if info.get("resolution") == "success" else 0.1
|
|
|
|
|
|
|
|
|
|
| 29 |
return 0.1
|
| 30 |
except Exception:
|
| 31 |
return 0.1
|