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

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
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"):
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):
return f"Error: File '{file}' does not exist."
@ -26,7 +28,7 @@ def execute_python_file(file):
'python:3.10',
f'python {file}',
volumes={
os.path.abspath(workspace_folder): {
os.path.abspath(WORKSPACE_FOLDER): {
'bind': '/workspace',
'mode': 'ro'}},
working_dir='/workspace',
@ -51,12 +53,18 @@ def execute_python_file(file):
def exec_shell(command_line):
print (f"Executing command '{command_line}' in workspace '{WORKSPACE_FOLDER}'")
args = command_line.split()
base_path = os.getcwd()
os.chdir(f"{base_path}/{WORKSPACE_FOLDER}")
result = subprocess.run(args, capture_output=True)
output = f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}";
os.chdir(base_path)
# print(f"Shell execution complete. Output: {output}")
return output