@@ -66,7 +66,11 @@ def initialize_session_state():
66
66
st .session_state .palm_langchain = None
67
67
if "gemini_langchain" not in st .session_state :
68
68
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
+
70
74
# Initialize session state for Vertex AI
71
75
if "vertexai" not in st .session_state :
72
76
st .session_state ["vertexai" ] = {
@@ -323,11 +327,12 @@ def main():
323
327
# Input box for entering the prompt
324
328
st .session_state .code_prompt = st .text_area ("Enter Prompt" , height = 200 , placeholder = placeholder ,label_visibility = 'hidden' )
325
329
326
- with st .expander ("Input/Output Options" ):
330
+ with st .expander ("Input Options" ):
327
331
with st .container ():
328
332
st .session_state .code_input = st .text_input ("Input (Stdin)" , placeholder = "Input (Stdin)" , label_visibility = 'collapsed' ,value = st .session_state .code_input )
329
333
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
+
331
336
# Set the input and output to None if the input and output is empty
332
337
if st .session_state .code_input and st .session_state .code_output :
333
338
if len (st .session_state .code_input ) == 0 :
@@ -344,22 +349,22 @@ def main():
344
349
345
350
with st .form ('code_controls_form' ):
346
351
# 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 )
348
353
349
354
# Input Box (for entering the file name) in the first column
350
355
with file_name_col :
351
356
code_file = st .text_input ("File name" , value = "" , placeholder = "File name" , label_visibility = 'collapsed' )
352
357
353
358
# Save Code button in the second column
354
359
with save_code_col :
355
- download_code_submitted = st .form_submit_button ("Download Code " )
360
+ download_code_submitted = st .form_submit_button ("Download" )
356
361
if download_code_submitted :
357
362
file_format = "text/plain"
358
363
st .session_state .download_link = general_utils .generate_download_link (st .session_state .generated_code , code_file ,file_format ,True )
359
364
360
365
# Generate Code button in the third column
361
366
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"
363
368
generate_submitted = st .form_submit_button (button_label )
364
369
365
370
if generate_submitted :
@@ -415,9 +420,21 @@ def main():
415
420
st .session_state .generated_code = ""
416
421
logger .error (f"Please select a valid AI option selected '{ st .session_state .ai_option } ' option" )
417
422
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
+
418
435
# Run Code button in the fourth column
419
436
with run_code_col :
420
- execute_submitted = st .form_submit_button ("Execute Code " )
437
+ execute_submitted = st .form_submit_button ("Execute" )
421
438
if execute_submitted :
422
439
st .session_state .output = general_utils .execute_code (st .session_state .compiler_mode )
423
440
0 commit comments