|
5 | 5 | from .correction import analyze_fsa_correction |
6 | 6 |
|
7 | 7 | def validate_fsa(value: str | dict) -> FSA: |
| 8 | + """Parse a FSA from JSON string or dict.""" |
8 | 9 | if isinstance(value, str): |
9 | 10 | return FSA.model_validate_json(value) |
10 | 11 | return FSA.model_validate(value) |
11 | 12 |
|
12 | | -def evaluation_function(payload: Any) -> LFResult: |
| 13 | +def evaluation_function( |
| 14 | + response: Any = None, |
| 15 | + answer: Any = None, |
| 16 | + params: Any = None # Temp workaround: treat params as Any |
| 17 | +) -> LFResult: |
13 | 18 | """ |
14 | | - Evaluate a student's FSA response against the expected answer. |
| 19 | + Temporary FSA evaluation function. |
15 | 20 | |
16 | 21 | Args: |
17 | | - payload: dict with keys 'response', 'answer', 'params' (front-end may wrap everything) |
| 22 | + response: Student's FSA (may be None if frontend wraps everything in params) |
| 23 | + answer: Expected FSA (may be None) |
| 24 | + params: Additional parameters (or full payload if frontend wraps everything here) |
18 | 25 | |
19 | 26 | Returns: |
20 | | - LFResult |
| 27 | + LFResult with is_correct and feedback_items |
21 | 28 | """ |
22 | 29 | try: |
23 | | - # Extract response/answer from the payload |
24 | | - raw_response = payload.get("response") or payload.get("params", {}).get("response") |
25 | | - raw_answer = payload.get("answer") or payload.get("params", {}).get("answer") |
26 | | - params = payload.get("params", {}) |
| 30 | + # Extract student and expected FSAs from whatever is present |
| 31 | + raw_response = response or getattr(params, "response", None) or params.get("response", None) |
| 32 | + raw_answer = answer or getattr(params, "answer", None) or params.get("answer", None) |
| 33 | + extra_params = params.get("params") or params |
27 | 34 |
|
28 | 35 | if raw_response is None or raw_answer is None: |
29 | | - raise ValueError("Missing response or answer in payload") |
| 36 | + raise ValueError("Missing FSA data: response or answer is None") |
30 | 37 |
|
31 | 38 | # Parse FSAs |
32 | 39 | student_fsa = validate_fsa(raw_response) |
33 | 40 | expected_fsa = validate_fsa(raw_answer) |
34 | 41 |
|
35 | | - require_minimal = params.get("require_minimal", False) |
| 42 | + require_minimal = extra_params.get("require_minimal", False) if isinstance(extra_params, dict) else False |
36 | 43 |
|
37 | | - # Run correction |
| 44 | + # Run correction pipeline |
38 | 45 | result: Result = analyze_fsa_correction(student_fsa, expected_fsa, require_minimal) |
39 | 46 |
|
40 | | - # Convert to LFResult |
| 47 | + # Return LFResult |
41 | 48 | return LFResult( |
42 | 49 | is_correct=result.is_correct, |
43 | 50 | feedback_items=[("feedback", result.feedback)] |
44 | 51 | ) |
45 | 52 |
|
46 | 53 | except Exception as e: |
| 54 | + # Always return LFResult with raw payload for debugging |
47 | 55 | return LFResult( |
48 | 56 | is_correct=False, |
49 | 57 | feedback_items=[( |
50 | 58 | "error", |
51 | | - f"Invalid FSA format: {str(e)}\n\npayload received:\n{payload}" |
| 59 | + f"Invalid FSA format: {str(e)}\n\n" |
| 60 | + f"response: {response}\nanswer: {answer}\nparams: {params}" |
52 | 61 | )] |
53 | 62 | ) |
0 commit comments