File size: 470 Bytes
6eba580
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import re

def evaluate_instruction_drift(response: str):
    violations = {
        "conciseness_violation": len(response.split()) > 120,
        "speculation_violation": bool(
            re.search(r"\b(might|could|possibly|likely)\b", response.lower())
        ),
        "uncertainty_missing": "uncertain" not in response.lower()
    }

    drift_score = round(
        sum(violations.values()) / len(violations),
        2
    )

    return violations, drift_score