2626from .base_node import BaseNode
2727from jsonschema import validate , ValidationError
2828
29-
3029class GenerateCodeNode (BaseNode ):
3130 """
3231 A node that generates Python code for a function that extracts data
@@ -96,7 +95,7 @@ def execute(self, state: dict) -> dict:
9695 Raises:
9796 KeyError: If the input keys are not found in the state, indicating
9897 that the necessary information for generating an answer is missing.
99- RuntimeError: If the maximum number of iterations is
98+ RuntimeError: If the maximum number of iterations is
10099 reached without obtaining the desired code.
101100 """
102101
@@ -170,7 +169,7 @@ def overall_reasoning_loop(self, state: dict) -> dict:
170169 self .logger .info (f"--- (Checking if the informations exctrcated are the ones Requested) ---" )
171170 state = self .semantic_comparison_loop (state )
172171 if state ["errors" ]["semantic" ]:
173- continue
172+ continue
174173 break
175174
176175 if state ["iteration" ] == self .max_iterations ["overall" ] and \
@@ -195,9 +194,9 @@ def syntax_reasoning_loop(self, state: dict) -> dict:
195194 state ["errors" ]["syntax" ] = [syntax_message ]
196195 self .logger .info (f"--- (Synax Error Found: { syntax_message } ) ---" )
197196 analysis = syntax_focused_analysis (state , self .llm_model )
198- self .logger .info (f"""--- (Regenerating Code
197+ self .logger .info (f"""--- (Regenerating Code
199198 to fix the Error) ---""" )
200- state ["generated_code" ] = syntax_focused_code_generation (state ,
199+ state ["generated_code" ] = syntax_focused_code_generation (state ,
201200 analysis , self .llm_model )
202201 state ["generated_code" ] = extract_code (state ["generated_code" ])
203202 return state
@@ -217,14 +216,14 @@ def execution_reasoning_loop(self, state: dict) -> dict:
217216 self .logger .info (f"--- (Code Execution Error: { execution_result } ) ---" )
218217 analysis = execution_focused_analysis (state , self .llm_model )
219218 self .logger .info (f"--- (Regenerating Code to fix the Error) ---" )
220- state ["generated_code" ] = execution_focused_code_generation (state ,
219+ state ["generated_code" ] = execution_focused_code_generation (state ,
221220 analysis , self .llm_model )
222221 state ["generated_code" ] = extract_code (state ["generated_code" ])
223222 return state
224223
225224 def validation_reasoning_loop (self , state : dict ) -> dict :
226225 for _ in range (self .max_iterations ["validation" ]):
227- validation , errors = self .validate_dict (state ["execution_result" ],
226+ validation , errors = self .validate_dict (state ["execution_result" ],
228227 self .output_schema .schema ())
229228 if validation :
230229 state ["errors" ]["validation" ] = []
@@ -240,7 +239,7 @@ def validation_reasoning_loop(self, state: dict) -> dict:
240239
241240 def semantic_comparison_loop (self , state : dict ) -> dict :
242241 for _ in range (self .max_iterations ["semantic" ]):
243- comparison_result = self .semantic_comparison (state ["execution_result" ],
242+ comparison_result = self .semantic_comparison (state ["execution_result" ],
244243 state ["reference_answer" ])
245244 if comparison_result ["are_semantically_equivalent" ]:
246245 state ["errors" ]["semantic" ] = []
@@ -342,7 +341,7 @@ def create_sandbox_and_execute(self, function_code):
342341 if not extract_data :
343342 raise NameError ("Function 'extract_data' not found in the generated code." )
344343
345- result = extract_data (self .raw_html )
344+ result = extract_data (self .raw_html )
346345 return True , result
347346 except Exception as e :
348347 return False , f"Error during execution: { str (e )} "
@@ -357,5 +356,5 @@ def validate_dict(self, data: dict, schema):
357356 validate (instance = data , schema = schema )
358357 return True , None
359358 except ValidationError as e :
360- errors = e . errors ()
359+ errors = [ e . message ]
361360 return False , errors
0 commit comments