Skip to content

Commit 8b7af44

Browse files
committed
Added AutoFix for PALM
1 parent e4784da commit 8b7af44

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

libs/general_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def execute_code(self, compiler_mode: str):
4747
if "error" in code_output.lower() or "exception" in code_output.lower() or "SyntaxError" in code_output.lower() or "NameError" in code_output.lower():
4848

4949
logger.error(f"Error in code execution: {code_output}")
50+
st.session_state.stderr = code_output
5051
response = st.session_state.sequential_chain({'code_topic': generated_code})
5152
fixed_code = response['code_fix']
5253
st.code(fixed_code, language=code_language.lower())

libs/palmai.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def fix_generated_code(self, code, code_language, fix_instructions=""):
209209

210210
logger.info(f"Fixing code")
211211
if code and len(code) > 0:
212-
logger.info(f"Fixing code {code[:100]}... in language {code_language}")
212+
logger.info(f"Fixing code {code[:100]}... in language {code_language} and error is {st.session_state.stderr}")
213213

214214
# Improved instructions template
215215
template = f"""
@@ -259,7 +259,10 @@ def fix_generated_code(self, code, code_language, fix_instructions=""):
259259
else:
260260
logger.warning("No module-related error found in the output.")
261261

262-
262+
else:
263+
st.toast("No error in previous execution.", icon="✅")
264+
return code
265+
263266
# Prompt Templates
264267
code_template = template
265268

script.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ def initialize_session_state():
6868
st.session_state.gemini_langchain = None
6969
if "code_fix_instructions" not in st.session_state:
7070
st.session_state.code_fix_instructions = None
71-
if "session_state.sequential_chain" not in st.session_state:
71+
if "sequential_chain" not in st.session_state:
7272
st.session_state.sequential_chain = None
73+
if "stderr" not in st.session_state:
74+
st.session_state.stderr = None
7375

7476
# Initialize session state for Vertex AI
7577
if "vertexai" not in st.session_state:
@@ -431,7 +433,6 @@ def main():
431433
logger.info(f"Fixing code with instructions: {st.session_state.code_fix_instructions}")
432434
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)
433435

434-
435436
# Run Code button in the fourth column
436437
with run_code_col:
437438
execute_submitted = st.form_submit_button("Execute")

0 commit comments

Comments
 (0)