Spaces:
Sleeping
Sleeping
| from models import Category, Priority, Status | |
| TASKS = { | |
| "classify_ticket": { | |
| "difficulty": "easy", | |
| "ticket": { | |
| "subject": "My invoice shows wrong amount", | |
| "description": "I was charged $150 but my plan is only $50/month. Please fix this immediately.", | |
| "expected_category": Category.billing, | |
| "expected_priority": Priority.high, | |
| }, | |
| }, | |
| "resolve_ticket": { | |
| "difficulty": "medium", | |
| "ticket": { | |
| "subject": "Cannot login to my account", | |
| "description": "I keep getting 'invalid password' error even after resetting my password twice. I need access urgently.", | |
| "expected_category": Category.account, | |
| "expected_priority": Priority.high, | |
| "resolution_keywords": ["password", "reset", "login", "account", "support", "help", "try", "clear", "browser", "cache"], | |
| }, | |
| }, | |
| "triage_queue": { | |
| "difficulty": "hard", | |
| "tickets": [ | |
| { | |
| "id": "t1", | |
| "subject": "System completely down for all users", | |
| "description": "Our entire team cannot access the platform. Business is halted.", | |
| "expected_priority": Priority.critical, | |
| "expected_category": Category.technical, | |
| }, | |
| { | |
| "id": "t2", | |
| "subject": "Question about pricing plans", | |
| "description": "Can you tell me the difference between basic and pro plans?", | |
| "expected_priority": Priority.low, | |
| "expected_category": Category.billing, | |
| }, | |
| { | |
| "id": "t3", | |
| "subject": "Package not delivered after 2 weeks", | |
| "description": "My order #12345 was supposed to arrive 2 weeks ago. No updates.", | |
| "expected_priority": Priority.high, | |
| "expected_category": Category.shipping, | |
| }, | |
| ], | |
| }, | |
| } | |
| def _clamp(score: float) -> float: | |
| """Ensure score is strictly between 0.0 and 1.0 (exclusive).""" | |
| return round(min(max(score, 0.01), 0.99), 2) | |
| def grade_classify_ticket(action: dict) -> float: | |
| task = TASKS["classify_ticket"]["ticket"] | |
| score = 0.1 | |
| if action.get("category") == task["expected_category"]: | |
| score += 0.44 | |
| if action.get("priority") == task["expected_priority"]: | |
| score += 0.44 | |
| return _clamp(score) | |
| def grade_resolve_ticket(action: dict) -> float: | |
| task = TASKS["resolve_ticket"]["ticket"] | |
| score = 0.1 | |
| if action.get("category") == task["expected_category"]: | |
| score += 0.15 | |
| if action.get("priority") == task["expected_priority"]: | |
| score += 0.15 | |
| resolution = (action.get("resolution") or "").lower() | |
| if len(resolution) > 20: | |
| score += 0.15 | |
| matched = sum(1 for kw in task["resolution_keywords"] if kw in resolution) | |
| score += min(matched / len(task["resolution_keywords"]), 0.89) * 0.35 | |
| return _clamp(score) | |
| def grade_triage_queue(actions: list) -> float: | |
| tickets = TASKS["triage_queue"]["tickets"] | |
| if not actions: | |
| return 0.01 | |
| total = 0.1 | |
| for i, ticket in enumerate(tickets): | |
| if i >= len(actions): | |
| break | |
| action = actions[i] | |
| if action.get("priority") == ticket["expected_priority"]: | |
| total += 0.28 | |
| if action.get("category") == ticket["expected_category"]: | |
| total += 0.28 | |
| return _clamp(total / len(tickets)) | |