Spaces:
Sleeping
Sleeping
Update env_tasks.py
Browse files- env_tasks.py +30 -73
env_tasks.py
CHANGED
|
@@ -1,68 +1,37 @@
|
|
| 1 |
-
from dataclasses import dataclass
|
| 2 |
-
from typing import Dict, Any, Tuple, List
|
| 3 |
-
|
| 4 |
-
from env_models import (
|
| 5 |
-
TicketObservation,
|
| 6 |
-
TriageAction,
|
| 7 |
-
TicketCategory,
|
| 8 |
-
TicketPriority,
|
| 9 |
-
Department,
|
| 10 |
-
EscalationDecision,
|
| 11 |
-
)
|
| 12 |
-
|
| 13 |
# βββ Helper βββββββββββββββββββββββββββββββββββββββββββββ
|
| 14 |
|
| 15 |
def _clamp(score: float) -> float:
|
|
|
|
| 16 |
if score >= 1.0:
|
| 17 |
-
return 0.
|
| 18 |
-
|
| 19 |
-
return 0.
|
| 20 |
return score
|
| 21 |
|
| 22 |
|
| 23 |
-
# βββ Dummy Tickets (keep minimal, your existing ones work too) βββββββββββββββ
|
| 24 |
-
|
| 25 |
-
TICKET_EASY = TicketObservation(
|
| 26 |
-
ticket_id="1",
|
| 27 |
-
subject="Laptop not working",
|
| 28 |
-
body="Laptop not booting",
|
| 29 |
-
reporter_name="User",
|
| 30 |
-
reporter_role="Employee",
|
| 31 |
-
system_info="Windows",
|
| 32 |
-
timestamp="now",
|
| 33 |
-
previous_tickets=0,
|
| 34 |
-
task_instruction="Classify",
|
| 35 |
-
valid_categories=[c.value for c in TicketCategory],
|
| 36 |
-
valid_priorities=[p.value for p in TicketPriority],
|
| 37 |
-
valid_departments=[d.value for d in Department],
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
TICKET_MEDIUM = TICKET_EASY
|
| 41 |
-
TICKET_HARD = TICKET_EASY
|
| 42 |
-
|
| 43 |
-
|
| 44 |
# βββ Graders βββββββββββββββββββββββββββββββββββββββββββββ
|
| 45 |
|
| 46 |
def grade_easy(action: TriageAction) -> Tuple[float, Dict[str, Any]]:
|
|
|
|
| 47 |
score = 0.0
|
| 48 |
-
breakdown = {}
|
| 49 |
|
| 50 |
if action.category == TicketCategory.HARDWARE:
|
| 51 |
-
score += 0.
|
| 52 |
|
| 53 |
if action.priority in {TicketPriority.HIGH, TicketPriority.CRITICAL}:
|
| 54 |
score += 0.25
|
| 55 |
|
| 56 |
-
if len(action.response) >
|
| 57 |
score += 0.15
|
| 58 |
|
| 59 |
score = _clamp(score)
|
|
|
|
| 60 |
return score, breakdown
|
| 61 |
|
| 62 |
|
| 63 |
def grade_medium(action: TriageAction) -> Tuple[float, Dict[str, Any]]:
|
|
|
|
| 64 |
score = 0.0
|
| 65 |
-
breakdown = {}
|
| 66 |
|
| 67 |
if action.category in {TicketCategory.NETWORK, TicketCategory.ACCESS}:
|
| 68 |
score += 0.25
|
|
@@ -74,66 +43,54 @@ def grade_medium(action: TriageAction) -> Tuple[float, Dict[str, Any]]:
|
|
| 74 |
score += 0.25
|
| 75 |
|
| 76 |
if action.escalate == EscalationDecision.ESCALATE:
|
| 77 |
-
score += 0.
|
| 78 |
|
| 79 |
-
if len(action.response) >
|
| 80 |
score += 0.15
|
| 81 |
|
| 82 |
score = _clamp(score)
|
|
|
|
| 83 |
return score, breakdown
|
| 84 |
|
| 85 |
|
| 86 |
def grade_hard(action: TriageAction) -> Tuple[float, Dict[str, Any]]:
|
|
|
|
| 87 |
score = 0.0
|
| 88 |
penalty = 0.0
|
| 89 |
-
breakdown = {}
|
| 90 |
|
| 91 |
if action.category == TicketCategory.SECURITY:
|
| 92 |
-
score += 0.
|
| 93 |
|
| 94 |
if action.priority == TicketPriority.CRITICAL:
|
| 95 |
-
score += 0.
|
| 96 |
|
| 97 |
if action.department == Department.SECURITY_TEAM:
|
| 98 |
-
score += 0.
|
| 99 |
|
| 100 |
if action.escalate == EscalationDecision.ESCALATE:
|
| 101 |
-
score += 0.
|
| 102 |
|
| 103 |
resp = action.response.lower()
|
| 104 |
|
| 105 |
-
if "disconnect"
|
| 106 |
score += 0.15
|
| 107 |
|
| 108 |
-
if "do not"
|
| 109 |
score += 0.15
|
| 110 |
|
| 111 |
-
if "decrypt" in resp:
|
| 112 |
-
penalty += 0.
|
| 113 |
-
|
| 114 |
-
raw = score - penalty
|
| 115 |
-
final = max(0.05, min(0.95, raw))
|
| 116 |
-
|
| 117 |
-
return final, breakdown
|
| 118 |
|
|
|
|
|
|
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
@dataclass
|
| 123 |
-
class Task:
|
| 124 |
-
task_id: str
|
| 125 |
-
name: str
|
| 126 |
-
description: str
|
| 127 |
-
difficulty: str
|
| 128 |
-
ticket: TicketObservation
|
| 129 |
-
grader: Any
|
| 130 |
-
max_steps: int = 1
|
| 131 |
|
|
|
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
Task("task_medium", "Medium", "Full triage", "medium", TICKET_MEDIUM, grade_medium),
|
| 136 |
-
Task("task_hard", "Hard", "Security incident", "hard", TICKET_HARD, grade_hard),
|
| 137 |
-
]
|
| 138 |
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# βββ Helper βββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
|
| 3 |
def _clamp(score: float) -> float:
|
| 4 |
+
# ALWAYS force strict (0,1)
|
| 5 |
if score >= 1.0:
|
| 6 |
+
return 0.99
|
| 7 |
+
if score <= 0.0:
|
| 8 |
+
return 0.01
|
| 9 |
return score
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# βββ Graders βββββββββββββββββββββββββββββββββββββββββββββ
|
| 13 |
|
| 14 |
def grade_easy(action: TriageAction) -> Tuple[float, Dict[str, Any]]:
|
| 15 |
+
breakdown: Dict[str, Any] = {}
|
| 16 |
score = 0.0
|
|
|
|
| 17 |
|
| 18 |
if action.category == TicketCategory.HARDWARE:
|
| 19 |
+
score += 0.60
|
| 20 |
|
| 21 |
if action.priority in {TicketPriority.HIGH, TicketPriority.CRITICAL}:
|
| 22 |
score += 0.25
|
| 23 |
|
| 24 |
+
if len(action.response) >= 30:
|
| 25 |
score += 0.15
|
| 26 |
|
| 27 |
score = _clamp(score)
|
| 28 |
+
breakdown["final_score"] = round(score, 4)
|
| 29 |
return score, breakdown
|
| 30 |
|
| 31 |
|
| 32 |
def grade_medium(action: TriageAction) -> Tuple[float, Dict[str, Any]]:
|
| 33 |
+
breakdown: Dict[str, Any] = {}
|
| 34 |
score = 0.0
|
|
|
|
| 35 |
|
| 36 |
if action.category in {TicketCategory.NETWORK, TicketCategory.ACCESS}:
|
| 37 |
score += 0.25
|
|
|
|
| 43 |
score += 0.25
|
| 44 |
|
| 45 |
if action.escalate == EscalationDecision.ESCALATE:
|
| 46 |
+
score += 0.10
|
| 47 |
|
| 48 |
+
if len(action.response) >= 50:
|
| 49 |
score += 0.15
|
| 50 |
|
| 51 |
score = _clamp(score)
|
| 52 |
+
breakdown["final_score"] = round(score, 4)
|
| 53 |
return score, breakdown
|
| 54 |
|
| 55 |
|
| 56 |
def grade_hard(action: TriageAction) -> Tuple[float, Dict[str, Any]]:
|
| 57 |
+
breakdown: Dict[str, Any] = {}
|
| 58 |
score = 0.0
|
| 59 |
penalty = 0.0
|
|
|
|
| 60 |
|
| 61 |
if action.category == TicketCategory.SECURITY:
|
| 62 |
+
score += 0.20
|
| 63 |
|
| 64 |
if action.priority == TicketPriority.CRITICAL:
|
| 65 |
+
score += 0.20
|
| 66 |
|
| 67 |
if action.department == Department.SECURITY_TEAM:
|
| 68 |
+
score += 0.20
|
| 69 |
|
| 70 |
if action.escalate == EscalationDecision.ESCALATE:
|
| 71 |
+
score += 0.10
|
| 72 |
|
| 73 |
resp = action.response.lower()
|
| 74 |
|
| 75 |
+
if any(k in resp for k in ["disconnect", "unplug", "network"]):
|
| 76 |
score += 0.15
|
| 77 |
|
| 78 |
+
if any(k in resp for k in ["do not", "don't", "avoid"]):
|
| 79 |
score += 0.15
|
| 80 |
|
| 81 |
+
if "decrypt" in resp or "recover" in resp:
|
| 82 |
+
penalty += 0.40
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
if "disconnect" not in resp:
|
| 85 |
+
penalty += 0.30
|
| 86 |
|
| 87 |
+
if action.escalate != EscalationDecision.ESCALATE:
|
| 88 |
+
penalty += 0.20
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
raw = score - penalty
|
| 91 |
|
| 92 |
+
# π₯ CRITICAL FIX
|
| 93 |
+
final = _clamp(raw)
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
breakdown["final_score"] = round(final, 4)
|
| 96 |
+
return final, breakdown
|