Migrate AutoGPT agent to poetry (#5219)

Inspired by #1102

* Migrate AutoGPT agent to poetry

  Co-authored-by: rickythefox <richard@ginzburg.se>

* Rewrite automatic dependency check (check_requirements.py) for poetry

* Sort dependencies

* Add instructions for poetry to README
This commit is contained in:
Reinier van der Leer
2023-09-15 05:18:44 +02:00
committed by GitHub
parent f3a112fca3
commit b21d68a8ab
16 changed files with 5087 additions and 149 deletions

View File

@@ -57,13 +57,13 @@ jobs:
- name: Set up Python dependency cache - name: Set up Python dependency cache
uses: actions/cache@v3 uses: actions/cache@v3
with: with:
path: ~/.cache/pip path: ~/.cache/pypoetry
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}-${{ steps.get_date.outputs.date }} key: ${{ runner.os }}-poetry-${{ hashFiles('autogpts/autogpt/pyproject.toml') }}-${{ steps.get_date.outputs.date }}
- name: Install dependencies - name: Install Python dependencies
run: | run: |
python -m pip install --upgrade pip curl -sSL https://install.python-poetry.org | python3 -
pip install -r requirements.txt poetry install
- name: Lint with flake8 - name: Lint with flake8
run: flake8 run: flake8
@@ -156,20 +156,21 @@ jobs:
- name: Set up Python dependency cache - name: Set up Python dependency cache
uses: actions/cache@v3 uses: actions/cache@v3
with: with:
path: ~/.cache/pip path: ~/.cache/pypoetry
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}-${{ steps.get_date.outputs.date }} key: ${{ runner.os }}-poetry-${{ hashFiles('autogpts/autogpt/pyproject.toml') }}-${{ steps.get_date.outputs.date }}
- name: Install Python dependencies - name: Install Python dependencies
run: | run: |
python -m pip install --upgrade pip curl -sSL https://install.python-poetry.org | python3 -
pip install -r requirements.txt poetry install
- name: Run pytest with coverage - name: Run pytest with coverage
run: | run: |
pytest -vv --cov=autogpt --cov-branch --cov-report term-missing --cov-report xml \ poetry run pytest -vv \
--cov=autogpt --cov-branch --cov-report term-missing --cov-report xml \
--numprocesses=logical --durations=10 \ --numprocesses=logical --durations=10 \
tests/unit tests/integration tests/challenges tests/unit tests/integration tests/challenges
python tests/challenges/utils/build_current_score.py poetry run python tests/challenges/utils/build_current_score.py
env: env:
CI: true CI: true
PROXY: ${{ github.event_name == 'pull_request_target' && secrets.PROXY || '' }} PROXY: ${{ github.event_name == 'pull_request_target' && secrets.PROXY || '' }}

View File

@@ -117,7 +117,7 @@ jobs:
run: | run: |
set +e set +e
test_output=$( test_output=$(
docker run --env CI --env OPENAI_API_KEY --entrypoint python ${{ env.IMAGE_NAME }} -m \ docker run --env CI --env OPENAI_API_KEY ${{ env.IMAGE_NAME }} run \
pytest -v --cov=autogpt --cov-branch --cov-report term-missing \ pytest -v --cov=autogpt --cov-branch --cov-report term-missing \
--numprocesses=4 --durations=10 \ --numprocesses=4 --durations=10 \
tests/unit tests/integration 2>&1 tests/unit tests/integration 2>&1

View File

@@ -162,8 +162,8 @@ jobs:
elif [ "$AGENT_NAME" == "Auto-GPT" ]; then elif [ "$AGENT_NAME" == "Auto-GPT" ]; then
python -m venv venv python -m venv venv
source venv/bin/activate source venv/bin/activate
pip install -r requirements.txt curl -sSL https://install.python-poetry.org | python3 -
pip uninstall agbenchmark -y poetry install --without benchmark
elif [ "$AGENT_NAME" == "mini-agi" ]; then elif [ "$AGENT_NAME" == "mini-agi" ]; then
python -m venv venv python -m venv venv
source venv/bin/activate source venv/bin/activate

View File

@@ -39,13 +39,13 @@ jobs:
- name: Set up Python dependency cache - name: Set up Python dependency cache
uses: actions/cache@v3 uses: actions/cache@v3
with: with:
path: ~/.cache/pip path: ~/.cache/pypoetry
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}-${{ steps.get_date.outputs.date }} key: ${{ runner.os }}-poetry-${{ hashFiles('autogpts/autogpt/pyproject.toml') }}-${{ steps.get_date.outputs.date }}
- name: Install Python dependencies - name: Install Python dependencies
run: | run: |
python -m pip install --upgrade pip curl -sSL https://install.python-poetry.org | python3 -
pip install -r requirements.txt poetry install
- name: Run pytest with coverage - name: Run pytest with coverage
run: | run: |

View File

@@ -46,11 +46,11 @@
// "forwardPorts": [], // "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created. // Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt", // "postCreateCommand": "poetry install",
// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. // Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode", "remoteUser": "vscode",
// Add the freshly containerized repo to the list of safe repositories // Add the freshly containerized repo to the list of safe repositories
"postCreateCommand": "git config --global --add safe.directory /workspace/Auto-GPT && pip3 install --user -r requirements.txt" "postCreateCommand": "git config --global --add safe.directory /workspace/Auto-GPT && poetry install"
} }

View File

@@ -9,6 +9,4 @@ logs/*
agbenchmark_config/logs/* agbenchmark_config/logs/*
agbenchmark_config/reports/* agbenchmark_config/reports/*
*.md
*.png *.png
!BULLETIN.md

View File

@@ -17,30 +17,37 @@ RUN apt-get update && apt-get install -y \
# Set environment variables # Set environment variables
ENV PIP_NO_CACHE_DIR=yes \ ENV PIP_NO_CACHE_DIR=yes \
PYTHONUNBUFFERED=1 \ PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 PYTHONDONTWRITEBYTECODE=1 \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=0 \
POETRY_NO_INTERACTION=1
# Install the required python packages globally # Install and configure Poetry
ENV PATH="$PATH:/root/.local/bin" RUN curl -sSL https://install.python-poetry.org | python3 -
COPY requirements.txt . ENV PATH="$POETRY_HOME/bin:$PATH"
RUN poetry config installer.max-workers 10
WORKDIR /app
COPY pyproject.toml poetry.lock ./
# Set the entrypoint # Set the entrypoint
ENTRYPOINT ["python", "-m", "autogpt", "--install-plugin-deps"] ENTRYPOINT ["poetry"]
CMD ["run", "autogpt", "--install-plugin-deps"]
# dev build -> include everything # dev build -> include everything
FROM autogpt-base as autogpt-dev FROM autogpt-base as autogpt-dev
RUN pip install --no-cache-dir -r requirements.txt RUN poetry install --no-root
WORKDIR /app
ONBUILD COPY . ./ ONBUILD COPY . ./
# release build -> include bare minimum # release build -> include bare minimum
FROM autogpt-base as autogpt-release FROM autogpt-base as autogpt-release
RUN sed -i '/Items below this point will not be included in the Docker Image/,$d' requirements.txt && \ RUN poetry install --no-root --without dev,benchmark
pip install --no-cache-dir -r requirements.txt
WORKDIR /app
ONBUILD COPY autogpt/ ./autogpt ONBUILD COPY autogpt/ ./autogpt
ONBUILD COPY scripts/ ./scripts ONBUILD COPY scripts/ ./scripts
ONBUILD COPY plugins/ ./plugins ONBUILD COPY plugins/ ./plugins
ONBUILD COPY prompt_settings.yaml ./prompt_settings.yaml ONBUILD COPY prompt_settings.yaml ./prompt_settings.yaml
ONBUILD COPY README.md ./README.md
ONBUILD RUN mkdir ./data ONBUILD RUN mkdir ./data
FROM autogpt-${BUILD_TYPE} AS auto-gpt FROM autogpt-${BUILD_TYPE} AS autogpt
RUN poetry install --only-root

View File

@@ -60,6 +60,11 @@ Please see the [documentation][docs] for full setup instructions and configurati
[docs/usage]: https://docs.agpt.co/usage/ [docs/usage]: https://docs.agpt.co/usage/
[docs/plugins]: https://docs.agpt.co/plugins/ [docs/plugins]: https://docs.agpt.co/plugins/
## 🏗️ Setting up for development
1. Make sure `poetry` is installed: `python3 -m pip install poetry`
2. Install all dependencies: `poetry install`
<h2 align="center"> 💖 Help Fund Auto-GPT's Development 💖</h2> <h2 align="center"> 💖 Help Fund Auto-GPT's Development 💖</h2>
<p align="center"> <p align="center">
If you can spare a coffee, you can help to cover the costs of developing Auto-GPT and help to push the boundaries of fully autonomous AI! If you can spare a coffee, you can help to cover the costs of developing Auto-GPT and help to push the boundaries of fully autonomous AI!

4913
autogpts/autogpt/poetry.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,25 +1,103 @@
[build-system] [tool.poetry]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "agpt" name = "agpt"
version = "0.4.7" version = "0.4.7"
authors = [ authors = [
{ name="Torantulino", email="support@agpt.co" }, "Significant Gravitas <support@agpt.co>",
] ]
readme = "README.md" readme = "README.md"
requires-python = ">=3.10" description = "An open-source attempt to make GPT-4 autonomous"
homepage = "https://github.com/Significant-Gravitas/Auto-GPT/tree/master/autogpts/autogpt"
classifiers = [ classifiers = [
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License", "License :: OSI Approved :: MIT License",
"Operating System :: OS Independent", "Operating System :: OS Independent",
] ]
description = "An open-source attempt to make GPT-4 autonomous" packages = [{ include = "autogpt" }]
[tool.poetry.scripts]
autogpt = "autogpt.app.cli:main"
[tool.poetry.dependencies]
python = "^3.10"
agent-protocol = "^0.2.3"
beautifulsoup4 = "^4.12.2"
charset-normalizer = "^3.1.0"
click = "*"
colorama = "^0.4.6"
distro = "^1.8.0"
docker = "*"
duckduckgo-search = "^3.0.2"
en-core-web-sm = {url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.5.0/en_core_web_sm-3.5.0-py3-none-any.whl"}
ftfy = "^6.1.1"
google-api-python-client = "*"
gTTS = "^2.3.1"
inflection = "*"
jsonschema = "*"
markdown = "*"
openai = "^0.27.10"
orjson = "^3.8.10"
Pillow = "*"
pinecone-client = "^2.2.1"
playsound = "~1.2.2"
prompt_toolkit = "^3.0.38"
pydantic = "*"
pylatexenc = "*"
PyPDF2 = "*"
python-docx = "*"
python-dotenv = "^1.0.0"
pyyaml = "^6.0"
readability-lxml = "^0.8.1"
redis = "*"
requests = "*"
selenium = "^4.11.2"
spacy = "^3.0.0"
tiktoken = "^0.3.3"
webdriver-manager = "*"
# web server
fastapi = "*"
uvicorn = "*"
# OpenAI and Generic plugins import
openapi-python-client = "^0.13.4"
[tool.poetry.group.dev.dependencies]
auto-gpt-plugin-template = {git = "https://github.com/Significant-Gravitas/Auto-GPT-Plugin-Template", rev = "0.1.0"}
black = "*"
coverage = "*"
flake8 = "*"
gitpython = "^3.1.32"
isort = "*"
mypy = "*"
numpy = "*"
pre-commit = "*"
types-beautifulsoup4 = "*"
types-colorama = "*"
types-Markdown = "*"
types-Pillow = "*"
# Testing dependencies
asynctest = "*"
pytest = "*"
pytest-asyncio = "*"
pytest-benchmark = "*"
pytest-cov = "*"
pytest-integration = "*"
pytest-mock = "*"
pytest-recording = "*"
pytest-xdist = "*"
vcrpy = {git = "https://github.com/Significant-Gravitas/vcrpy.git", rev = "master"}
[tool.poetry.group.benchmark.dependencies]
agbenchmark = "0.0.9"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[project.urls]
"Homepage" = "https://github.com/Significant-Gravitas/Auto-GPT"
"Bug Tracker" = "https://github.com/Significant-Gravitas/Auto-GPT"
[tool.black] [tool.black]
line-length = 88 line-length = 88
@@ -56,6 +134,7 @@ skip = '''
''' '''
[tool.pytest.ini_options] [tool.pytest.ini_options]
markers = [ markers = [
"requires_openai_api_key", "requires_openai_api_key",

View File

@@ -1,71 +0,0 @@
beautifulsoup4>=4.12.2
colorama==0.4.6
distro==1.8.0
openai==0.27.8
playsound==1.2.2
python-dotenv==1.0.0
pyyaml==6.0
PyPDF2
python-docx
markdown
pylatexenc
readability-lxml==0.8.1
requests
tiktoken==0.3.3
gTTS==2.3.1
docker
duckduckgo-search==3.0.2
google-api-python-client #(https://developers.google.com/custom-search/v1/overview)
pinecone-client==2.2.1
redis
orjson==3.8.10
ftfy>=6.1.1
Pillow
selenium>=4.11.2
webdriver-manager
jsonschema
click
charset-normalizer>=3.1.0
spacy>=3.0.0,<4.0.0
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.5.0/en_core_web_sm-3.5.0-py3-none-any.whl
prompt_toolkit>=3.0.38
pydantic
inflection
agbenchmark>=0.0.9
agent-protocol>=0.1.1
# web server
fastapi
uvicorn
##Dev
coverage
flake8
numpy
pre-commit
black
isort
gitpython>=3.1.32
auto-gpt-plugin-template @ git+https://github.com/Significant-Gravitas/Auto-GPT-Plugin-Template@0.1.0
mypy
types-Markdown
types-beautifulsoup4
types-colorama
types-Pillow
# OpenAI and Generic plugins import
openapi-python-client==0.13.4
# Items below this point will not be included in the Docker Image
# Testing dependencies
pytest
asynctest
pytest-asyncio
pytest-benchmark
pytest-cov
pytest-integration
pytest-mock
vcrpy @ git+https://github.com/Significant-Gravitas/vcrpy.git@master
pytest-recording
pytest-xdist

View File

@@ -15,10 +15,13 @@ pause
exit /B 1 exit /B 1
:Found :Found
%PYTHON_CMD% scripts/check_requirements.py requirements.txt %PYTHON_CMD% scripts/check_requirements.py
if errorlevel 1 ( if errorlevel 1 (
echo Installing missing packages... echo
%PYTHON_CMD% -m pip install -r requirements.txt %PYTHON_CMD% -m poetry install --without dev
echo
echo Finished installing packages! Starting AutoGPT...
echo
) )
%PYTHON_CMD% -m autogpt %* %PYTHON_CMD% -m autogpt %*
pause pause

View File

@@ -16,14 +16,16 @@ function find_python_command() {
PYTHON_CMD=$(find_python_command) PYTHON_CMD=$(find_python_command)
if $PYTHON_CMD -c "import sys; sys.exit(sys.version_info < (3, 10))"; then if $PYTHON_CMD -c "import sys; sys.exit(sys.version_info < (3, 10))"; then
$PYTHON_CMD scripts/check_requirements.py requirements.txt $PYTHON_CMD scripts/check_requirements.py
if [ $? -eq 1 ] if [ $? -eq 1 ]
then then
echo Installing missing packages... echo
$PYTHON_CMD -m pip install -r requirements.txt $PYTHON_CMD -m poetry install --without dev
echo
echo "Finished installing packages! Starting AutoGPT..."
echo
fi fi
$PYTHON_CMD -m autogpt "$@" $PYTHON_CMD -m autogpt "$@"
read -p "Press any key to continue..."
else else
echo "Python 3.10 or higher is required to run Auto GPT." echo "Python 3.10 or higher is required to run Auto GPT."
fi fi

View File

@@ -1,36 +1,37 @@
import re import contextlib
import os
import sys import sys
from importlib.metadata import version
import pkg_resources try:
import poetry.factory
except ModuleNotFoundError:
os.system(f"{sys.executable} -m pip install 'poetry>=1.6.1,<2.0.0'")
from poetry.factory import Factory
from poetry.core.constraints.version.version import Version
def main(): def main():
requirements_file = sys.argv[1] poetry_project = Factory().create_poetry()
with open(requirements_file, "r") as f: # repository = poetry_project.locker.locked_repository()
required_packages = [ # dependencies = repository.packages
line.strip().split("#")[0].strip() for line in f.readlines() dependency_group = poetry_project.package.dependency_group("main")
]
installed_packages = {pkg.key: pkg.version for pkg in pkg_resources.working_set}
missing_packages = [] missing_packages = []
for required_package in required_packages: for dep in dependency_group.dependencies:
if not required_package: # Skip empty lines # Try to verify that the installed version is suitable
with contextlib.suppress(ModuleNotFoundError):
installed_version = version(dep.name) # if this fails -> not installed
if dep.constraint.allows(Version.parse(installed_version)):
continue continue
pkg = pkg_resources.Requirement.parse(required_package) # If the above verification fails, mark the package as missing
if ( missing_packages.append(str(dep))
pkg.key not in installed_packages
or pkg_resources.parse_version(installed_packages[pkg.key])
not in pkg.specifier
):
missing_packages.append(str(pkg))
if missing_packages: if missing_packages:
print("Missing packages:") print("Missing packages:")
print(", ".join(missing_packages)) print(", ".join(missing_packages))
sys.exit(1) sys.exit(1)
else:
print("All packages are installed.")
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -153,14 +153,14 @@ data objects. To set up a Weaviate database, check out their [Quickstart Tutoria
Although still experimental, [Embedded Weaviate](https://weaviate.io/developers/weaviate/installation/embedded) Although still experimental, [Embedded Weaviate](https://weaviate.io/developers/weaviate/installation/embedded)
is supported which allows the Auto-GPT process itself to start a Weaviate instance. is supported which allows the Auto-GPT process itself to start a Weaviate instance.
To enable it, set `USE_WEAVIATE_EMBEDDED` to `True` and make sure you `pip install "weaviate-client>=3.15.4"`. To enable it, set `USE_WEAVIATE_EMBEDDED` to `True` and make sure you `poetry add weaviate-client@^3.15.4`.
#### Install the Weaviate client #### Install the Weaviate client
Install the Weaviate client before usage. Install the Weaviate client before usage.
```shell ```shell
$ pip install weaviate-client $ poetry add weaviate-client
``` ```
#### Setting up environment variables #### Setting up environment variables

View File

@@ -230,8 +230,8 @@ docker run -it --env-file=.env -v $PWD:/app --rm auto-gpt --gpt3only --continuou
Create a virtual environment to run in. Create a virtual environment to run in.
```shell ```shell
python -m venv venvAutoGPT python -m venv .venv
source venvAutoGPT/bin/activate source .venv/bin/activate
pip3 install --upgrade pip pip3 install --upgrade pip
``` ```