|
5 | 5 | from .schemas.result import Result |
6 | 6 | from .correction import analyze_fsa_correction |
7 | 7 |
|
8 | | -def evaluation_function( |
9 | | - payload: Any |
10 | | -) -> LFResult: |
11 | | - return LFResult( |
12 | | - is_correct=False, |
13 | | - feedback_items=[("error", f"{payload}")] |
14 | | - ) |
15 | | - |
16 | 8 | # def evaluation_function( |
17 | | -# response: Any, |
18 | | -# answer: Any, |
19 | | -# params: Params, |
| 9 | +# payload: Any |
20 | 10 | # ) -> LFResult: |
21 | | -# """ |
22 | | -# Evaluate a student's FSA response against the expected answer. |
| 11 | +# return LFResult( |
| 12 | +# is_correct=False, |
| 13 | +# feedback_items=[("error", f"{payload}")] |
| 14 | +# ) |
| 15 | + |
| 16 | +def evaluation_function( |
| 17 | + response: Any, |
| 18 | + answer: Any, |
| 19 | + params: Params, |
| 20 | +) -> LFResult: |
| 21 | + """ |
| 22 | + Evaluate a student's FSA response against the expected answer. |
23 | 23 | |
24 | | -# Args: |
25 | | -# response: Student's FSA (dict with states, alphabet, transitions, etc.), since frontend constriants, this is FSAFrontend |
26 | | -# answer: Expected FSA still, FSAFrontend for the same reason |
27 | | -# params: Extra parameters (e.g., require_minimal) |
| 24 | + Args: |
| 25 | + response: Student's FSA (dict with states, alphabet, transitions, etc.), since frontend constriants, this is FSAFrontend |
| 26 | + answer: Expected FSA still, FSAFrontend for the same reason |
| 27 | + params: Extra parameters (e.g., require_minimal) |
28 | 28 | |
29 | | -# Returns: |
30 | | -# LFResult with is_correct and feedback |
31 | | -# """ |
32 | | -# try: |
33 | | -# # Parse FSAs from input |
34 | | -# student_fsa_ = FSAFrontend.model_validate(response) |
35 | | -# expected_fsa_ = FSAFrontend.model_validate(answer) |
| 29 | + Returns: |
| 30 | + LFResult with is_correct and feedback |
| 31 | + """ |
| 32 | + try: |
| 33 | + # Parse FSAs from input |
| 34 | + student_fsa_ = FSAFrontend.model_validate(response) |
| 35 | + expected_fsa_ = FSAFrontend.model_validate(answer) |
36 | 36 |
|
37 | | -# student_fsa = student_fsa_.from_flattened() |
38 | | -# expected_fsa = expected_fsa_.from_flattened() |
| 37 | + student_fsa = student_fsa_.from_flattened() |
| 38 | + expected_fsa = expected_fsa_.from_flattened() |
39 | 39 |
|
40 | 40 |
|
41 | | -# # Get require_minimal from params if present |
42 | | -# require_minimal = params.get("require_minimal", False) if hasattr(params, "get") else False |
| 41 | + # Get require_minimal from params if present |
| 42 | + require_minimal = params.get("require_minimal", False) if hasattr(params, "get") else False |
43 | 43 |
|
44 | | -# # Run correction pipeline |
45 | | -# result: Result = analyze_fsa_correction(student_fsa, expected_fsa, require_minimal) |
| 44 | + # Run correction pipeline |
| 45 | + result: Result = analyze_fsa_correction(student_fsa, expected_fsa, require_minimal) |
46 | 46 |
|
47 | | -# # Convert to lf_toolkit Result |
48 | | -# return LFResult( |
49 | | -# is_correct=result.is_correct, |
50 | | -# feedback_items=[("feedback", result.feedback)] |
51 | | -# ) |
| 47 | + # Convert to lf_toolkit Result |
| 48 | + return LFResult( |
| 49 | + is_correct=result.is_correct, |
| 50 | + feedback_items=[("feedback", result.feedback)] |
| 51 | + ) |
52 | 52 |
|
53 | | -# except Exception as e: |
54 | | -# return LFResult( |
55 | | -# is_correct=False, |
56 | | -# feedback_items=[("error", f"Invalid FSA format: {str(e)}, received: \n\nresponse: {response}\n\n answer: {answer}, \n\nparams: {params}")] |
57 | | -# ) |
| 53 | + except Exception as e: |
| 54 | + return LFResult( |
| 55 | + is_correct=False, |
| 56 | + feedback_items=[("error", f"Invalid FSA format: {str(e)}, received: \n\nresponse: {response}\n\n answer: {answer}, \n\nparams: {params}")] |
| 57 | + ) |
0 commit comments