-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluation.py
More file actions
executable file
·51 lines (39 loc) · 1.63 KB
/
evaluation.py
File metadata and controls
executable file
·51 lines (39 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from typing import Any
from lf_toolkit.evaluation import Result as LFResult, Params
from .schemas import FSA, FSAFrontend
from .schemas.result import Result
from .correction import analyze_fsa_correction
def evaluation_function(
response: Any,
answer: Any,
params: Params,
) -> LFResult:
"""
Evaluate a student's FSA response against the expected answer.
Args:
response: Student's FSA (dict with states, alphabet, transitions, etc.), since frontend constriants, this is FSAFrontend
answer: Expected FSA still, FSAFrontend for the same reason
params: Extra parameters (e.g., require_minimal)
Returns:
LFResult with is_correct and feedback
"""
try:
# Parse FSAs from input
student_fsa_ = FSAFrontend.model_validate(response)
expected_fsa_ = FSAFrontend.model_validate(answer)
student_fsa = student_fsa_.from_flattened()
expected_fsa = expected_fsa_.from_flattened()
# Get require_minimal from params if present
require_minimal = params.get("require_minimal", False) if hasattr(params, "get") else False
# Run correction pipeline
result: Result = analyze_fsa_correction(student_fsa, expected_fsa, require_minimal)
# Convert to lf_toolkit Result
return LFResult(
is_correct=result.is_correct,
feedback_items=[("feedback", result.feedback)]
)
except Exception as e:
return LFResult(
is_correct=False,
feedback_items=[("error", f"Invalid FSA format: {str(e)}, received: {response}")]
)