Spaces:
Runtime error
Runtime error
| from .policy import check_policy | |
| def grade(action, task, steps): | |
| score = 0.0 | |
| # π― Category | |
| if action.category == task["expected_category"]: | |
| score += 0.3 | |
| else: | |
| score -= 0.3 | |
| # π― Action | |
| if action.action_type == task["expected_action"]: | |
| score += 0.3 | |
| else: | |
| score += 0.05 | |
| # π― Response QUALITY (VERY STRICT) | |
| if action.response_text: | |
| text = action.response_text.lower() | |
| if len(text) > 20: | |
| score += 0.2 | |
| else: | |
| score -= 0.2 # β penalize short response | |
| if "sorry" in text: | |
| score += 0.1 | |
| # domain signals | |
| if task["expected_category"] == "billing" and "refund" in text: | |
| score += 0.1 | |
| if task["expected_category"] == "security" and "secure" in text: | |
| score += 0.1 | |
| else: | |
| score -= 0.3 | |
| # π― Efficiency | |
| if steps <= 2: | |
| score += 0.1 | |
| else: | |
| score -= 0.2 | |
| # π― Policy penalty | |
| violations = check_policy(action, action.category or "") | |
| score -= 0.3 * len(violations) | |
| return max(0.0, min(1.0, score)), str(violations) |