Skip to content

Commit b99ac82

Browse files
authored
Merge pull request #29 from lambda-feedback/payload
fix: try with one single payload
2 parents e9f2d9a + 1d4475b commit b99ac82

1 file changed

Lines changed: 23 additions & 39 deletions

File tree

evaluation_function/evaluation.py

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,53 @@
11
from typing import Any
2-
from lf_toolkit.evaluation import Result as LFResult, Params
3-
4-
# note: this file is a temperary workaround, if the frontend -> backend communication succeed, fix this file
5-
6-
from .schemas import FSA#, FSAFrontend
2+
from lf_toolkit.evaluation import Result as LFResult
3+
from .schemas import FSA
74
from .schemas.result import Result
85
from .correction import analyze_fsa_correction
96

10-
# def evaluation_function(
11-
# payload: Any
12-
# ) -> LFResult:
13-
# return LFResult(
14-
# is_correct=False,
15-
# feedback_items=[("error", f"{payload}")]
16-
# )
17-
187
def validate_fsa(value: str | dict) -> FSA:
198
if isinstance(value, str):
209
return FSA.model_validate_json(value)
2110
return FSA.model_validate(value)
2211

23-
def evaluation_function(
24-
response: Any,
25-
answer: Any,
26-
params: Params,
27-
) -> LFResult:
12+
def evaluation_function(payload: Any) -> LFResult:
2813
"""
2914
Evaluate a student's FSA response against the expected answer.
3015
3116
Args:
32-
response: Student's FSA (dict with states, alphabet, transitions, etc.), since frontend constriants, this is FSAFrontend
33-
answer: Expected FSA still, FSAFrontend for the same reason
34-
params: Extra parameters (e.g., require_minimal)
17+
payload: dict with keys 'response', 'answer', 'params' (front-end may wrap everything)
3518
3619
Returns:
37-
LFResult with is_correct and feedback
20+
LFResult
3821
"""
3922
try:
40-
# Parse FSAs from input
41-
# student_fsa_ = FSAFrontend.model_validate(response)
42-
# expected_fsa_ = FSAFrontend.model_validate(answer)
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", {})
4327

44-
# student_fsa = student_fsa_.from_flattened()
45-
# expected_fsa = expected_fsa_.from_flattened()
28+
if raw_response is None or raw_answer is None:
29+
raise ValueError("Missing response or answer in payload")
4630

47-
# as a temporary workaround we assume the response and answer are all valid json strings
48-
student_fsa = validate_fsa(response)
49-
expected_fsa = validate_fsa(answer)
31+
# Parse FSAs
32+
student_fsa = validate_fsa(raw_response)
33+
expected_fsa = validate_fsa(raw_answer)
5034

35+
require_minimal = params.get("require_minimal", False)
5136

52-
53-
# Get require_minimal from params if present
54-
require_minimal = params.get("require_minimal", False) if hasattr(params, "get") else False
55-
56-
# Run correction pipeline
37+
# Run correction
5738
result: Result = analyze_fsa_correction(student_fsa, expected_fsa, require_minimal)
58-
59-
# Convert to lf_toolkit Result
39+
40+
# Convert to LFResult
6041
return LFResult(
6142
is_correct=result.is_correct,
6243
feedback_items=[("feedback", result.feedback)]
6344
)
64-
45+
6546
except Exception as e:
6647
return LFResult(
6748
is_correct=False,
68-
feedback_items=[("error", f"Invalid FSA format: {str(e)}, received: \n\nresponse: {response}\n\n answer: {answer}, \n\nparams: {params}")]
49+
feedback_items=[(
50+
"error",
51+
f"Invalid FSA format: {str(e)}\n\npayload received:\n{payload}"
52+
)]
6953
)

0 commit comments

Comments
 (0)