Skip to content

Commit 08ccb1a

Browse files
committed
feat: accept json stringified response
1 parent 38c8b58 commit 08ccb1a

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

evaluation_function/evaluation.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any
2+
import json
23
from lf_toolkit.evaluation import Result, Params
34

45
from evaluation_function.domain.evaluators import _extract_atoms, EquivalenceEvaluator, SatisfiabilityEvaluator, TautologyEvaluator
@@ -37,13 +38,23 @@ def evaluation_function(
3738
return types and that evaluation_function() is the main function used
3839
to output the evaluation response.
3940
"""
40-
41+
4142
if not isinstance(answer, str):
4243
return Result(
4344
is_correct=False,
4445
feedback_items=[("incorrect input", "missing answer object")]
4546
)
4647

48+
# If response is a string, parse it as JSON
49+
if isinstance(response, str):
50+
try:
51+
response = json.loads(response)
52+
except json.JSONDecodeError as e:
53+
return Result(
54+
is_correct=False,
55+
feedback_items=[("incorrect input", f"response is not valid JSON: {str(e)}")]
56+
)
57+
4758
if not isinstance(response, dict):
4859
return Result(
4960
is_correct=False,

0 commit comments

Comments
 (0)