Skip to content

Commit

Permalink
Convert to python module named autogpt.
Browse files Browse the repository at this point in the history
Also fixed the Dockerfile.
Converting to module makes development easier.
Fixes coverage script in CI and test imports.
  • Loading branch information
dhensen authored and waynehamadi committed Apr 14, 2023
1 parent a17a850 commit d64f866
Show file tree
Hide file tree
Showing 45 changed files with 352 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ jobs:
- name: Lint with flake8
continue-on-error: false
run: flake8 scripts/ tests/ --select E303,W293,W291,W292,E305,E231,E302
run: flake8 autogpt/ tests/ --select E303,W293,W291,W292,E305,E231,E302

- name: Run unittest tests with coverage
run: |
coverage run --source=scripts -m unittest discover tests
coverage run --source=autogpt -m unittest discover tests
- name: Generate coverage report
run: |
Expand Down
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
scripts/keys.py
scripts/*json
scripts/node_modules/
scripts/__pycache__/keys.cpython-310.pyc
autogpt/keys.py
autogpt/*json
autogpt/node_modules/
autogpt/__pycache__/keys.cpython-310.pyc
package-lock.json
*.pyc
auto_gpt_workspace/*
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ COPY --chown=appuser:appuser requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt

# Copy the application files
COPY --chown=appuser:appuser scripts/ .
COPY --chown=appuser:appuser autogpt/ .

# Set the entrypoint
ENTRYPOINT ["python", "main.py"]
ENTRYPOINT ["python", "-m", "autogpt"]
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ pip install -r requirements.txt

## 🔧 Usage

1. Run the `main.py` Python script in your terminal:
1. Run the `autogpt` Python module in your terminal:
_(Type this into your CMD window)_

```
python scripts/main.py
python -m autogpt
```

2. After each of action, enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter additional feedback for the AI.
Expand All @@ -136,7 +136,21 @@ You will find activity and error logs in the folder `./output/logs`
To output debug logs:

```
python scripts/main.py --debug
python -m autogpt --debug
```

### Docker

You can also build this into a docker image and run it:

```
docker build -t autogpt .
docker run -it --env-file=./.env -v $PWD/auto_gpt_workspace:/app/auto_gpt_workspace autogpt
```

You can pass extra arguments, for instance, running with `--gpt3only` and `--continuous` mode:
```
docker run -it --env-file=./.env -v $PWD/auto_gpt_workspace:/app/auto_gpt_workspace autogpt --gpt3only --continuous
```
### Command Line Arguments
Here are some common arguments you can use when running Auto-GPT:
Expand All @@ -152,7 +166,7 @@ Here are some common arguments you can use when running Auto-GPT:
Use this to use TTS for Auto-GPT

```
python scripts/main.py --speak
python -m autogpt --speak
```

## 🔍 Google API Keys Configuration
Expand Down Expand Up @@ -328,10 +342,10 @@ Continuous mode is not recommended.
It is potentially dangerous and may cause your AI to run forever or carry out actions you would not usually authorise.
Use at your own risk.

1. Run the `main.py` Python script in your terminal:
1. Run the `autogpt` python module in your terminal:

```
python scripts/main.py --continuous
python -m autogpt --speak --continuous
```

Expand All @@ -342,7 +356,7 @@ python scripts/main.py --continuous
If you don't have access to the GPT4 api, this mode will allow you to use Auto-GPT!

```
python scripts/main.py --gpt3only
python -m autogpt --speak --gpt3only
```

It is recommended to use a virtual machine for tasks that require high security measures to prevent any potential harm to the main computer's system and data.
Expand Down Expand Up @@ -415,8 +429,8 @@ This project uses [flake8](https://flake8.pycqa.org/en/latest/) for linting. We
To run the linter, run the following command:

```
flake8 scripts/ tests/
flake8 autogpt/ tests/
# Or, if you want to run flake8 with the same configuration as the CI:
flake8 scripts/ tests/ --select E303,W293,W291,W292,E305,E231,E302
flake8 autogpt/ tests/ --select E303,W293,W291,W292,E305,E231,E302
```
File renamed without changes.
18 changes: 9 additions & 9 deletions scripts/main.py → autogpt/__main__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import json
import random
import commands as cmd
import utils
from memory import get_memory, get_supported_memory_backends
import chat
from autogpt import commands as cmd
from autogpt import utils
from autogpt.memory import get_memory, get_supported_memory_backends
from autogpt import chat
from colorama import Fore, Style
from spinner import Spinner
from autogpt.spinner import Spinner
import time
import speak
from config import Config
from json_parser import fix_and_parse_json
from ai_config import AIConfig
from autogpt import speak
from autogpt.config import Config
from autogpt.json_parser import fix_and_parse_json
from autogpt.ai_config import AIConfig
import traceback
import yaml
import argparse
Expand Down
2 changes: 1 addition & 1 deletion scripts/agent_manager.py → autogpt/agent_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from llm_utils import create_chat_completion
from autogpt.llm_utils import create_chat_completion

next_key = 0
agents = {} # key, (task, full_message_history, model)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions scripts/ai_functions.py → autogpt/ai_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List
import json
from config import Config
from call_ai_function import call_ai_function
from autogpt.config import Config
from autogpt.call_ai_function import call_ai_function
cfg = Config()


Expand Down
6 changes: 3 additions & 3 deletions scripts/browse.py → autogpt/browse.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import requests
from bs4 import BeautifulSoup
from memory import get_memory
from config import Config
from llm_utils import create_chat_completion
from autogpt.memory import get_memory
from autogpt.config import Config
from autogpt.llm_utils import create_chat_completion
from urllib.parse import urlparse, urljoin

cfg = Config()
Expand Down
5 changes: 2 additions & 3 deletions scripts/call_ai_function.py → autogpt/call_ai_function.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from config import Config

from autogpt.config import Config
cfg = Config()

from llm_utils import create_chat_completion
from autogpt.llm_utils import create_chat_completion


# This is a magic function that can do anything with no-code. See
Expand Down
8 changes: 4 additions & 4 deletions scripts/chat.py → autogpt/chat.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import time
import openai
from dotenv import load_dotenv
from config import Config
import token_counter
from llm_utils import create_chat_completion
from logger import logger
from autogpt.config import Config
from autogpt import token_counter
from autogpt.llm_utils import create_chat_completion
from autogpt.logger import logger
import logging

cfg = Config()
Expand Down
20 changes: 10 additions & 10 deletions scripts/commands.py → autogpt/commands.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import browse
from autogpt import browse
import json
from memory import get_memory
from autogpt.memory import get_memory
import datetime
import agent_manager as agents
import speak
from config import Config
import ai_functions as ai
from file_operations import read_file, write_to_file, append_to_file, delete_file, search_files
from execute_code import execute_python_file, execute_shell
from json_parser import fix_and_parse_json
from image_gen import generate_image
import autogpt.agent_manager as agents
from autogpt import speak
from autogpt.config import Config
import autogpt.ai_functions as ai
from autogpt.file_operations import read_file, write_to_file, append_to_file, delete_file, search_files
from autogpt.execute_code import execute_python_file, execute_shell
from autogpt.json_parser import fix_and_parse_json
from autogpt.image_gen import generate_image
from duckduckgo_search import ddg
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions scripts/data_ingestion.py → autogpt/data_ingestion.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import argparse
import logging
from config import Config
from memory import get_memory
from file_operations import ingest_file, search_files
from autogpt.config import Config
from autogpt.memory import get_memory
from autogpt.file_operations import ingest_file, search_files

cfg = Config()

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/image_gen.py → autogpt/image_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import io
import os.path
from PIL import Image
from config import Config
from autogpt.config import Config
import uuid
import openai
from base64 import b64decode
Expand Down
8 changes: 4 additions & 4 deletions scripts/json_parser.py → autogpt/json_parser.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
from typing import Any, Dict, Union
from call_ai_function import call_ai_function
from config import Config
from json_utils import correct_json
from logger import logger
from autogpt.call_ai_function import call_ai_function
from autogpt.config import Config
from autogpt.json_utils import correct_json
from autogpt.logger import logger

cfg = Config()

Expand Down
2 changes: 1 addition & 1 deletion scripts/json_utils.py → autogpt/json_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import json
from config import Config
from autogpt.config import Config

cfg = Config()

Expand Down
2 changes: 1 addition & 1 deletion scripts/llm_utils.py → autogpt/llm_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
import openai
from colorama import Fore
from config import Config
from autogpt.config import Config

cfg = Config()

Expand Down
6 changes: 3 additions & 3 deletions scripts/logger.py → autogpt/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

from colorama import Style

import speak
from config import Config
from config import Singleton
from autogpt import speak
from autogpt.config import Config
from autogpt.config import Singleton

cfg = Config()

Expand Down
4 changes: 2 additions & 2 deletions scripts/memory/__init__.py → autogpt/memory/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from memory.local import LocalCache
from memory.no_memory import NoMemory
from autogpt.memory.local import localcache
from autogpt.memory.no_memory import NoMemory

# List of supported memory backends
# Add a backend to this list if the import attempt is successful
Expand Down
2 changes: 1 addition & 1 deletion scripts/memory/base.py → autogpt/memory/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Base class for memory providers."""
import abc
from config import AbstractSingleton, Config
from autogpt.config import AbstractSingleton, Config
import openai

cfg = Config()
Expand Down
2 changes: 1 addition & 1 deletion scripts/memory/local.py → autogpt/memory/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, List, Optional
import numpy as np
import os
from memory.base import MemoryProviderSingleton, get_ada_embedding
from autogpt.memory.base import MemoryProviderSingleton, get_ada_embedding


EMBED_DIM = 1536
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions scripts/memory/pinecone.py → autogpt/memory/pinecone.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from autogpt.config import Config, Singleton

import pinecone

Expand Down
4 changes: 2 additions & 2 deletions scripts/memory/redismem.py → autogpt/memory/redismem.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
import numpy as np

from memory.base import MemoryProviderSingleton, get_ada_embedding
from logger import logger
from autogpt.memory.base import MemoryProviderSingleton, get_ada_embedding
from autogpt.logger import logger
from colorama import Fore, Style


Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/speak.py → autogpt/speak.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from playsound import playsound
import requests
from config import Config
from autogpt.config import Config
cfg = Config()
import gtts
import threading
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- redis
build: ./
volumes:
- "./scripts:/app"
- "./autogpt:/app"
- ".env:/app/.env"
profiles: ["exclude-from-up"]

Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from scripts.main import main
from autogpt import main
Loading

0 comments on commit d64f866

Please sign in to comment.