Optionally return shell output on incorrect command (#894) (#899)

This allows the LLM to correct its previous command by looking at the
error message output to the shell.

Additionally, this uses subprocess.run because that is now recommended
over subprocess.check_output:

https://docs.python.org/3/library/subprocess.html#using-the-subprocess-module

Co-authored-by: Amos Ng <me@amos.ng>
This commit is contained in:
Harrison Chase
2023-02-06 12:46:16 -08:00
committed by GitHub
parent 3aa53b44dd
commit 93a091cfb8
2 changed files with 18 additions and 2 deletions

View File

@@ -21,6 +21,13 @@ def test_incorrect_command() -> None:
assert output == "Command 'invalid_command' returned non-zero exit status 127."
def test_incorrect_command_return_err_output() -> None:
"""Test optional returning of shell output on incorrect command."""
session = BashProcess(return_err_output=True)
output = session.run(["invalid_command"])
assert output == "/bin/sh: 1: invalid_command: not found\n"
def test_create_directory_and_files(tmp_path: Path) -> None:
"""Test creation of a directory and files in a temporary directory."""
session = BashProcess(strip_newlines=True)