@@ -66,7 +66,11 @@ def initialize_session_state():
6666 st .session_state .palm_langchain = None
6767 if "gemini_langchain" not in st .session_state :
6868 st .session_state .gemini_langchain = None
69-
69+ if "code_fix_instructions" not in st .session_state :
70+ st .session_state .code_fix_instructions = None
71+ if "session_state.sequential_chain" not in st .session_state :
72+ st .session_state .sequential_chain = None
73+
7074 # Initialize session state for Vertex AI
7175 if "vertexai" not in st .session_state :
7276 st .session_state ["vertexai" ] = {
@@ -323,11 +327,12 @@ def main():
323327 # Input box for entering the prompt
324328 st .session_state .code_prompt = st .text_area ("Enter Prompt" , height = 200 , placeholder = placeholder ,label_visibility = 'hidden' )
325329
326- with st .expander ("Input/Output Options" ):
330+ with st .expander ("Input Options" ):
327331 with st .container ():
328332 st .session_state .code_input = st .text_input ("Input (Stdin)" , placeholder = "Input (Stdin)" , label_visibility = 'collapsed' ,value = st .session_state .code_input )
329333 st .session_state .code_output = st .text_input ("Output (Stdout)" , placeholder = "Output (Stdout)" , label_visibility = 'collapsed' ,value = st .session_state .code_output )
330-
334+ st .session_state .code_fix_instructions = st .text_input ("Fix instructions" , placeholder = "Fix instructions" , label_visibility = 'collapsed' ,value = st .session_state .code_fix_instructions )
335+
331336 # Set the input and output to None if the input and output is empty
332337 if st .session_state .code_input and st .session_state .code_output :
333338 if len (st .session_state .code_input ) == 0 :
@@ -344,22 +349,22 @@ def main():
344349
345350 with st .form ('code_controls_form' ):
346351 # Create columns for alignment
347- file_name_col , save_code_col ,generate_code_col ,run_code_col = st .columns (4 )
352+ file_name_col , save_code_col ,generate_code_col ,run_code_col , fix_code_col = st .columns (5 )
348353
349354 # Input Box (for entering the file name) in the first column
350355 with file_name_col :
351356 code_file = st .text_input ("File name" , value = "" , placeholder = "File name" , label_visibility = 'collapsed' )
352357
353358 # Save Code button in the second column
354359 with save_code_col :
355- download_code_submitted = st .form_submit_button ("Download Code " )
360+ download_code_submitted = st .form_submit_button ("Download" )
356361 if download_code_submitted :
357362 file_format = "text/plain"
358363 st .session_state .download_link = general_utils .generate_download_link (st .session_state .generated_code , code_file ,file_format ,True )
359364
360365 # Generate Code button in the third column
361366 with generate_code_col :
362- button_label = "Generate Code " if st .session_state ["vertexai" ]["model_name" ] == "code-bison" else "Complete Code "
367+ button_label = "Generate" if st .session_state ["vertexai" ]["model_name" ] == "code-bison" else "Complete"
363368 generate_submitted = st .form_submit_button (button_label )
364369
365370 if generate_submitted :
@@ -415,9 +420,21 @@ def main():
415420 st .session_state .generated_code = ""
416421 logger .error (f"Please select a valid AI option selected '{ st .session_state .ai_option } ' option" )
417422
423+ # Fix Code button in the fourth column
424+ with fix_code_col :
425+ fix_submitted = st .form_submit_button ("Auto Fix" )
426+ if fix_submitted :
427+ if len (st .session_state .code_fix_instructions ) == 0 :
428+ st .toast ("Missing fix instructions" , icon = "❌" )
429+ logger .warning ("Missing fix instructions" )
430+
431+ logger .info (f"Fixing code with instructions: { st .session_state .code_fix_instructions } " )
432+ st .session_state .generated_code = st .session_state .palm_langchain .fix_generated_code (st .session_state .generated_code , st .session_state .code_language ,st .session_state .code_fix_instructions )
433+
434+
418435 # Run Code button in the fourth column
419436 with run_code_col :
420- execute_submitted = st .form_submit_button ("Execute Code " )
437+ execute_submitted = st .form_submit_button ("Execute" )
421438 if execute_submitted :
422439 st .session_state .output = general_utils .execute_code (st .session_state .compiler_mode )
423440
0 commit comments