Significant-Gravitas / AutoGPT

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
https://agpt.co
Other
167.92k stars 44.33k forks source link

Agent unable to run python code written using write_to_file prompt #4822

Closed sulaimonao closed 1 year ago

sulaimonao commented 1 year ago

⚠️ Search for existing issues first ⚠️

Which Operating System are you using?

MacOS

Which version of Auto-GPT are you using?

Latest Release

Do you use OpenAI GPT-3 or GPT-4?

GPT-3.5

Which area covers your issue best?

Installation and setup

Describe your issue.

During my prompt (write a rap song about coding in the style of Eminem), agent wrote some python codes (not sure why), but is unable to run/execute the file. Leads to a loop and then an error parsing json

Screen Shot 2023-06-27 at 1 51 43 PM Screen Shot 2023-06-27 at 1 56 48 PM Screen Shot 2023-06-27 at 12 56 45 PM

[Uploading activity.log…]() error.log

Upload Activity Log Content

No response

Upload Error Log Content

No response

a1264113629 commented 1 year ago

AutoGPT runs Python scripts within a container. To use AutoGPT, you have two options: either install Docker (which allows AutoGPT to initiate a temporary container for script execution) or directly run AutoGPT inside a container. I prefer starting run.sh in an existing container that already has Python and common packages installed. This also helps to save the execution time.

sulaimonao commented 1 year ago

AutoGPT runs Python scripts within a container. To use AutoGPT, you have two options: either install Docker (which allows AutoGPT to initiate a temporary container for script execution) or directly run AutoGPT inside a container. I prefer starting run.sh in an existing container that already has Python and common packages installed. This also helps to save the execution time.

I have docker Installed not sure what the issue is

tomtom94 commented 1 year ago

I am touching the exact same part of the code, I am not sure we are talking about the same issue but myself I got the logs

Image 'python:3-alpine' found locally 
SYSTEM: Command execute_python_code returned: Traceback (most recent call last): File "/workspace/FSGPT/executed_code/fibonacci.py", line 1, in <module> import openpyxl ModuleNotFoundError: No module named 'openpyxl'

First line Auto-GPT runs in a container python:3-alpine no worries about that. But then in the python code there is a line import openpyxl but this module needs to be installed and is not in python:3-alpine default docker image...

I have been trying to make a conversation on Discord https://discord.com/channels/1092243196446249134/1092266131110236170/1123560112989163540

Auto-GPT isn't able to install python modules in the docker container they need to be used. Whatever how you run Auto-GPT with docker or with python straight.

For me there are 2 alternatives:

I have been trying to make a regex to find all the import in a file https://github.com/Significant-Gravitas/Auto-GPT/pull/4847/files#diff-3a17cf79b7ab8e6b1ea66d34144971f6bb366c5638a666af493889d91f4cac5aR103

regex_imports = re.findall(r"import (.*(?=\n))", code)

It's kind of working...

gatepoet commented 1 year ago

I am touching the exact same part of the code, I am not sure we are talking about the same issue but myself I got the logs

Image 'python:3-alpine' found locally 
SYSTEM: Command execute_python_code returned: Traceback (most recent call last): File "/workspace/FSGPT/executed_code/fibonacci.py", line 1, in <module> import openpyxl ModuleNotFoundError: No module named 'openpyxl'

First line Auto-GPT runs in a container python:3-alpine no worries about that. But then in the python code there is a line import openpyxl but this module needs to be installed and is not in python:3-alpine default docker image...

I have been trying to make a conversation on Discord https://discord.com/channels/1092243196446249134/1092266131110236170/1123560112989163540

Auto-GPT isn't able to install python modules in the docker container they need to be used. Whatever how you run Auto-GPT with docker or with python straight.

For me there are 2 alternatives:

  • We could ask to GPT to make a Dockerfile ready to go and the requirements.txt,
  • Otherwise we need to compute one in Auto-GPT with a regex.

I have been trying to make a regex to find all the import in a file https://github.com/Significant-Gravitas/Auto-GPT/pull/4847/files#diff-3a17cf79b7ab8e6b1ea66d34144971f6bb366c5638a666af493889d91f4cac5aR103

regex_imports = re.findall(r"import (.*(?=\n))", code)

It's kind of working...

You might be onto another problem here, that seems to arise when executing python files from AutoGPT outside of docker and needing to install requirements. I was executing with both docker compose and devcontainer, and I was experience the same issue. In my case the problem was that AutoGPT didn't realize that it was in a container and tried to start a new one for the code execution.

github-actions[bot] commented 1 year ago

This issue has automatically been marked as stale because it has not had any activity in the last 50 days. You can unstale it by commenting or removing the label. Otherwise, this issue will be closed in 10 days.

github-actions[bot] commented 1 year ago

This issue was closed automatically because it has been stale for 10 days with no activity.