@@ -49,90 +49,46 @@ def evaluation_function(
4949
5050 # If response is a string, parse it as JSON
5151 if isinstance (response , str ):
52- try :
53- response = json .loads (response )
54- except json .JSONDecodeError as e :
55- return Result (
56- is_correct = False ,
57- feedback_items = [("incorrect input" , f"response is not valid JSON: { str (e )} " )]
58- )
52+ response = json .loads (response )
5953
6054 if not isinstance (response , dict ):
6155 return Result (
6256 is_correct = False ,
6357 feedback_items = [("incorrect input" , "missing response object" )]
6458 )
6559
66-
6760 response_formula = response .get ("formula" , None )
6861 if not isinstance (response_formula , str ):
6962 return Result (
7063 is_correct = False ,
7164 feedback_items = [("incorrect input" , "response must be type String" )]
7265 )
7366
74- # parse response_formula into Formula
75- try :
76- formula = formula_parser (response_formula )
77-
78- except BuildError as e :
79- return Result (
80- is_correct = False ,
81- feedback_items = [(BuildError , str (e ))]
82- )
83- except ValueError as e :
84- return Result (
85- is_correct = False ,
86- feedback_items = [(ValueError , str (e ))]
87- )
88-
89-
67+ formula = formula_parser (response_formula )
9068
9169 # check if input is a truth table
9270 truth_table = response .get ("truthTable" , None )
9371 if truth_table is not None and isinstance (truth_table , dict ):
94-
9572 variables = truth_table .get ("variables" , [])
9673 cells = truth_table .get ("cells" , [])
97-
74+
9875 if not isinstance (variables , list ) or not isinstance (cells , list ):
9976 return Result (
10077 is_correct = False ,
10178 feedback_items = [("incorrect input" , "truthTable must contain 'variables' and 'cells' arrays" )]
10279 )
10380
104- # tokenise answer
105- try :
106- answer_formula = formula_parser (answer )
107-
108- except BuildError as e :
109- return Result (
110- is_correct = False ,
111- feedback_items = [("BuildError" , str (e ))]
112- )
113- except ValueError as e :
114- return Result (
115- is_correct = False ,
116- feedback_items = [("ValueError" , str (e ))]
117- )
118-
81+ answer_formula = formula_parser (answer )
11982 num_atoms = len (_extract_atoms (answer_formula ))
120-
121- # Evaluate the truth table
83+
12284 truth_table_result = evaluate_truth_table (variables , cells , num_atoms )
12385 if not truth_table_result .is_correct :
12486 return truth_table_result
12587
126-
127-
128- # check only one of "equivilance", "tautology", "satisfiability" is selected
129-
13088 equivalence = params .get ("equivalence" , False )
13189 tautology = params .get ("tautology" , False )
13290 satisfiability = params .get ("satisfiability" , False )
13391
134-
135- #check that 1 and only 1 param is selected
13692 num_selected = sum ([equivalence , tautology , satisfiability ])
13793
13894 if num_selected == 0 :
@@ -146,38 +102,17 @@ def evaluation_function(
146102 feedback_items = [("invalid param" , "please only select 1 param" )]
147103 )
148104
149-
150- feedback = None
151105 is_correct = False
152-
153-
154106 if equivalence :
155-
156- # tokenise answer
157- try :
158- answer_formula = formula_parser (answer )
159-
160- except BuildError as e :
161- return Result (
162- is_correct = False ,
163- feedback_items = [(BuildError , str (e ))]
164- )
165- except ValueError as e :
166- return Result (
167- is_correct = False ,
168- feedback_items = [(ValueError , str (e ))]
169- )
170-
107+ answer_formula = formula_parser (answer )
171108 is_correct = EquivalenceEvaluator (formula , answer_formula ).evaluate ()
172-
173-
174109 elif tautology :
175110 is_correct = TautologyEvaluator (formula ).evaluate ()
176111 elif satisfiability :
177112 is_correct = SatisfiabilityEvaluator (formula ).evaluate ()
178113
179114 return Result (is_correct = is_correct )
180-
115+
181116 except Exception as e :
182117 return Result (
183118 is_correct = False ,
0 commit comments