@@ -305,45 +305,38 @@ def chat(
305305 text ,
306306 function_code ,
307307 thought_process ,
308- ) = cls .code_generator_brain .parse_openai_response (response )
309-
310-
311-
312-
308+ ) = cls .code_generator_brain .parse_openai_response (response )
313309
314310 with open ("temp_for_debug.json" , "w" ) as f :
315311 out = {'function_code' : function_code ,
316312 'query' : rephrased_user_msg }
317313 json .dump (out , f , indent = 4 )
318- # handle_function_codes gives the answer with function outputs
314+ # handle_function_codes gives the answer with function outputs
319315 amadeus_answer = cls .core_loop (
320316 rephrased_user_msg , text , function_code , thought_process
321317 )
322- amadeus_answer = amadeus_answer .asdict ()
323-
324318 # export the generated function to code_output
325- if amadeus_answer [ ' function_code' ] and code_output != "" :
319+ if amadeus_answer . function_code and code_output != "" :
326320 cls .export_function_code (
327- original_user_msg , amadeus_answer [ " function_code" ] , code_output
321+ original_user_msg , amadeus_answer . function_code , code_output
328322 )
329323
330324 # if there is an error or the function code is empty, we want to make sure we prevent ChatGPT to learn to output nothing from few-shot learning
331325 # is this used anymore?
332- if amadeus_answer [ " has_error" ] :
326+ if amadeus_answer . has_error :
333327 cls .code_generator_brain .context_window [- 1 ][
334328 "content"
335329 ] += "\n While executing the code above, there was error so it is not correct answer\n "
336330
337- elif amadeus_answer [ " has_error" ] :
331+ elif amadeus_answer . has_error :
338332 cls .code_generator_brain .context_window .pop ()
339333 cls .code_generator_brain .history .pop ()
340334 else :
341335 # needs to manage memory of Amadeus for context window management and state restore etc.
342336 # we have it remember user's original question instead of the rephrased one for better
343337 cls .code_generator_brain .manage_memory (
344- original_user_msg , copy .deepcopy (amadeus_answer )
345- )
346-
338+ original_user_msg , amadeus_answer
339+ )
347340 return amadeus_answer
348341
349342 # this should become an async function so the user can continue to ask question
@@ -354,7 +347,7 @@ def execute_python_function(
354347 function_code ,
355348 ):
356349 # we might register a few helper functions into globals()
357- result = None
350+ result = None
358351 exec (function_code , globals ())
359352 if "task_program" not in globals ():
360353 return None
@@ -534,8 +527,8 @@ def collect_function_result(cls, function_returns, function_code, thought_proces
534527 function_returns , function_code , thought_process
535528 )
536529
537- if cls .plot :
538- plt .show ()
530+ # if cls.plot:
531+ # plt.show()
539532
540533 # deduplicate as both events and plot could append plots
541534 return amadeus_answer
@@ -608,9 +601,7 @@ def chat_iteration(cls, user_input, code_output="", functions=None, rephrased=[]
608601 code_output = code_output ,
609602 functions = functions ,
610603 )
611- if not isinstance (answer , AmadeusAnswer ):
612- answer = AmadeusAnswer .fromdict (answer )
613-
604+
614605 return answer
615606
616607 # @classmethod
@@ -653,19 +644,19 @@ def compile_amadeus_answer_when_no_error(
653644 ):
654645 explanation = cls .explainer_brain .generate_explanation (
655646 user_query ,
656- amadeus_answer [ " chain_of_thoughts" ] ,
657- amadeus_answer [ " str_answer" ] ,
658- amadeus_answer [ " plots" ]
647+ amadeus_answer . chain_of_thoughts ,
648+ amadeus_answer . str_answer ,
649+ amadeus_answer . plots
659650 )
660- amadeus_answer [ " summary" ] = explanation
651+ amadeus_answer . summary = explanation
661652 AmadeusLogger .info ("Generated explanation from the explainer:" )
662653 AmadeusLogger .info (explanation )
663654 else :
664- amadeus_answer [ " summary" ] = ""
655+ amadeus_answer . summary = ""
665656 else :
666657 # if gpt apologies or asks for clarification, it will be no error but no function
667658 amadeus_answer = AmadeusAnswer ()
668- amadeus_answer [ " chain_of_thoughts" ] = thought_process
659+ amadeus_answer . chain_of_thoughts = thought_process
669660 return amadeus_answer
670661
671662 @classmethod
0 commit comments