Skip to content

Commit

Permalink
only initiate error-correction if return code != 0
Browse files Browse the repository at this point in the history
  • Loading branch information
granawkins committed Feb 16, 2024
1 parent b4617e2 commit 51a01e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/rawdog/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def rawdog(prompt: str, config, llm_client):
):
llm_client.add_message("user", "User chose not to run script")
break
output, error = execute_script(script, llm_client)
output, error, return_code = execute_script(script, llm_client)
elif message:
print(message)
except KeyboardInterrupt:
break

_continue = (
output and output.strip().endswith("CONTINUE") or error and retries > 0
_continue = (output and output.strip().endswith("CONTINUE")) or (
return_code != 0 and error and retries > 0
)
if error:
retries -= 1
Expand Down
5 changes: 3 additions & 2 deletions src/rawdog/execute_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def install_pip_packages(*packages: str):
)


def execute_script(script: str, llm_client) -> str:
def execute_script(script: str, llm_client) -> tuple[str, str, int]:
python_executable = get_rawdog_python_executable()
with tempfile.NamedTemporaryFile(mode="w+", delete=False) as tmp_script:
tmp_script_name = tmp_script.name
Expand All @@ -51,6 +51,7 @@ def execute_script(script: str, llm_client) -> str:
)
output = result.stdout
error = result.stderr
return_code = result.returncode
if error and "ModuleNotFoundError: No module named" in error:
match = re.search(r"No module named '(\w+)'", error)
if match:
Expand All @@ -70,4 +71,4 @@ def execute_script(script: str, llm_client) -> str:
retry = True
else:
print("Failed to install package")
return output, error
return output, error, return_code

0 comments on commit 51a01e4

Please sign in to comment.