Change working directory during shell command execution

pull/463/head
Bernhard Mueller 2023-04-10 10:26:54 +07:00
parent 955b83c136
commit dd469bf2ae
3 changed files with 20 additions and 12 deletions

View File

@ -1,7 +1,6 @@
ai_goals: ai_goals:
- Increase net worth. - Increase net worth
- Develop and manage multiple businesses autonomously. - Grow Twitter Account
- Play to your strengths as a Large Language Model. - Develop and manage multiple businesses autonomously
ai_name: Entrepreneur-GPT ai_name: A helpful assistant.
ai_role: an AI designed to autonomously develop and run businesses with the sole goal ai_role: Run the command "pwd" on the shell and return the result
of increasing your net worth.

1
auto-gpt.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -3,15 +3,17 @@ import os
import subprocess import subprocess
def execute_python_file(file): WORKSPACE_FOLDER = "auto_gpt_workspace"
workspace_folder = "auto_gpt_workspace"
print (f"Executing file '{file}' in workspace '{workspace_folder}'")
def execute_python_file(file):
print (f"Executing file '{file}' in workspace '{WORKSPACE_FOLDER}'")
if not file.endswith(".py"): if not file.endswith(".py"):
return "Error: Invalid file type. Only .py files are allowed." return "Error: Invalid file type. Only .py files are allowed."
file_path = os.path.join(workspace_folder, file) file_path = os.path.join(WORKSPACE_FOLDER, file)
if not os.path.isfile(file_path): if not os.path.isfile(file_path):
return f"Error: File '{file}' does not exist." return f"Error: File '{file}' does not exist."
@ -26,7 +28,7 @@ def execute_python_file(file):
'python:3.10', 'python:3.10',
f'python {file}', f'python {file}',
volumes={ volumes={
os.path.abspath(workspace_folder): { os.path.abspath(WORKSPACE_FOLDER): {
'bind': '/workspace', 'bind': '/workspace',
'mode': 'ro'}}, 'mode': 'ro'}},
working_dir='/workspace', working_dir='/workspace',
@ -51,12 +53,18 @@ def execute_python_file(file):
def exec_shell(command_line): def exec_shell(command_line):
print (f"Executing command '{command_line}' in workspace '{WORKSPACE_FOLDER}'")
args = command_line.split() args = command_line.split()
base_path = os.getcwd()
os.chdir(f"{base_path}/{WORKSPACE_FOLDER}")
result = subprocess.run(args, capture_output=True) result = subprocess.run(args, capture_output=True)
output = f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}"; output = f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}";
os.chdir(base_path)
# print(f"Shell execution complete. Output: {output}") # print(f"Shell execution complete. Output: {output}")
return output return output