Skip to content

Commit

Permalink
Merge branch 'master' into prompt-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
AlrikOlson committed Apr 13, 2023
2 parents 2a62394 + ff52b20 commit 9b256a3
Show file tree
Hide file tree
Showing 25 changed files with 178 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Lint with flake8
continue-on-error: false
run: flake8 scripts/ tests/ --select E303,W293,W291,W292,E305
run: flake8 scripts/ tests/ --select E303,W293,W291,W292,E305,E231,E302

- name: Run unittest tests with coverage
run: |
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,32 @@ Optional:

To install Auto-GPT, follow these steps:

0. Make sure you have all the **requirements** above, if not, install/get them.
1. Make sure you have all the **requirements** above, if not, install/get them.

_The following commands should be executed in a CMD, Bash or Powershell window. To do this, go to a folder on your computer, click in the folder path at the top and type CMD, then press enter._

1. Clone the repository:
2. Clone the repository:
For this step you need Git installed, but you can just download the zip file instead by clicking the button at the top of this page ☝️

```
git clone https://github.com/Torantulino/Auto-GPT.git
```

2. Navigate to the project directory:
3. Navigate to the project directory:
_(Type this into your CMD window, you're aiming to navigate the CMD window to the repository you just downloaded)_

```
cd 'Auto-GPT'
```

3. Install the required dependencies:
4. Install the required dependencies:
_(Again, type this into your CMD window)_

```
pip install -r requirements.txt
```

4. Rename `.env.template` to `.env` and fill in your `OPENAI_API_KEY`. If you plan to use Speech Mode, fill in your `ELEVEN_LABS_API_KEY` as well.
5. Rename `.env.template` to `.env` and fill in your `OPENAI_API_KEY`. If you plan to use Speech Mode, fill in your `ELEVEN_LABS_API_KEY` as well.
- Obtain your OpenAI API key from: https://platform.openai.com/account/api-keys.
- Obtain your ElevenLabs API key from: https://elevenlabs.io. You can view your xi-api-key using the "Profile" tab on the website.
- If you want to use GPT on an Azure instance, set `USE_AZURE` to `True` and then:
Expand Down Expand Up @@ -348,11 +348,13 @@ coverage run -m unittest discover tests

## Run linter

This project uses [flake8](https://flake8.pycqa.org/en/latest/) for linting. To run the linter, run the following command:
This project uses [flake8](https://flake8.pycqa.org/en/latest/) for linting. We currently use the following rules: `E303,W293,W291,W292,E305,E231,E302`. See the [flake8 rules](https://www.flake8rules.com/) for more information.

To run the linter, run the following command:

```
flake8 scripts/ tests/
# Or, if you want to run flake8 with the same configuration as the CI:
flake8 scripts/ tests/ --select E303,W293,W291,W292,E305
```
flake8 scripts/ tests/ --select E303,W293,W291,W292,E305,E231,E302
```
1 change: 1 addition & 0 deletions azure.yaml.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
azure_api_type: azure_ad
azure_api_base: your-base-url-for-azure
azure_api_version: api-version-for-azure
azure_model_map:
Expand Down
1 change: 1 addition & 0 deletions scripts/agent_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Create new GPT agent
# TODO: Centralise use of create_chat_completion() to globally enforce token limit


def create_agent(task, prompt, model):
"""Create a new agent and return its key"""
global next_key
Expand Down
1 change: 1 addition & 0 deletions scripts/ai_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from prompt import get_prompt


class AIConfig:
"""
A class object that contains the configuration information for the AI
Expand Down
2 changes: 2 additions & 0 deletions scripts/call_ai_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
cfg = Config()

from llm_utils import create_chat_completion


# This is a magic function that can do anything with no-code. See
# https://github.com/Torantulino/AI-Functions for more info.
def call_ai_function(function, args, description, model=None):
Expand Down
1 change: 1 addition & 0 deletions scripts/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

cfg = Config()


def create_chat_message(role, content):
"""
Create a chat message with the given role and content.
Expand Down
3 changes: 3 additions & 0 deletions scripts/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def is_valid_int(value):
except ValueError:
return False


def get_command(response):
"""Parse the response and return the command name and arguments"""
try:
Expand Down Expand Up @@ -135,6 +136,7 @@ def google_search(query, num_results=8):

return json.dumps(search_results, ensure_ascii=False, indent=4)


def google_official_search(query, num_results=8):
"""Return the results of a google search using the official Google API"""
from googleapiclient.discovery import build
Expand Down Expand Up @@ -171,6 +173,7 @@ def google_official_search(query, num_results=8):
# Return the list of search result URLs
return search_results_links


def browse_website(url, question):
"""Browse a website and return the summary and links"""
summary = get_text_summary(url, question)
Expand Down
12 changes: 6 additions & 6 deletions scripts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ def __init__(self):
self.smart_token_limit = int(os.getenv("SMART_TOKEN_LIMIT", 8000))

self.openai_api_key = os.getenv("OPENAI_API_KEY")
self.temperature = int(os.getenv("TEMPERATURE", "1"))
self.use_azure = False
self.temperature = float(os.getenv("TEMPERATURE", "1"))
self.use_azure = os.getenv("USE_AZURE") == 'True'
self.execute_local_commands = os.getenv('EXECUTE_LOCAL_COMMANDS', 'False') == 'True'

if self.use_azure:
self.load_azure_config()
openai.api_type = "azure"
openai.api_type = self.openai_api_type
openai.api_base = self.openai_api_base
openai.api_version = self.openai_api_version

Expand All @@ -73,7 +72,7 @@ def __init__(self):

# User agent headers to use when browsing web
# Some websites might just completely deny request with an error code if no user agent was found.
self.user_agent_header = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"}
self.user_agent_header = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"}
self.redis_host = os.getenv("REDIS_HOST", "localhost")
self.redis_port = os.getenv("REDIS_PORT", "6379")
self.redis_password = os.getenv("REDIS_PASSWORD", "")
Expand Down Expand Up @@ -121,8 +120,9 @@ def load_azure_config(self, config_file: str=AZURE_CONFIG_FILE) -> None:
config_params = yaml.load(file, Loader=yaml.FullLoader)
except FileNotFoundError:
config_params = {}
self.openai_api_base = config_params.get("azure_api_base", "")
self.openai_api_version = config_params.get("azure_api_version", "")
self.openai_api_type = os.getenv("OPENAI_API_TYPE", config_params.get("azure_api_type", "azure"))
self.openai_api_base = os.getenv("OPENAI_AZURE_API_BASE", config_params.get("azure_api_base", ""))
self.openai_api_version = os.getenv("OPENAI_AZURE_API_VERSION", config_params.get("azure_api_version", ""))
self.azure_model_to_deployment_id_map = config_params.get("azure_model_map", [])

def set_continuous_mode(self, value: bool):
Expand Down
1 change: 1 addition & 0 deletions scripts/execute_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def execute_python_file(file):
except Exception as e:
return f"Error: {str(e)}"


def execute_shell(command_line):

current_dir = os.getcwd()
Expand Down
3 changes: 2 additions & 1 deletion scripts/file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def write_to_file(filename, text):
directory = os.path.dirname(filepath)
if not os.path.exists(directory):
os.makedirs(directory)
with open(filepath, "w") as f:
with open(filepath, "w", encoding='utf-8') as f:
f.write(text)
return "File written to successfully."
except Exception as e:
Expand All @@ -65,6 +65,7 @@ def delete_file(filename):
except Exception as e:
return "Error: " + str(e)


def search_files(directory):
found_files = []

Expand Down
1 change: 1 addition & 0 deletions scripts/image_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

working_directory = "auto_gpt_workspace"


def generate_image(prompt):

filename = str(uuid.uuid4()) + ".jpg"
Expand Down
1 change: 1 addition & 0 deletions scripts/llm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

openai.api_key = cfg.openai_api_key


# Overly simple abstraction until we create something better
def create_chat_completion(messages, model=None, temperature=cfg.temperature, max_tokens=None)->str:
"""Create a chat completion using the OpenAI API"""
Expand Down
9 changes: 5 additions & 4 deletions scripts/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def emit(self, record):
except Exception:
self.handleError(record)


class ConsoleHandler(logging.StreamHandler):
def emit(self, record):
msg = self.format(record)
Expand All @@ -166,11 +167,11 @@ def emit(self, record):
self.handleError(record)


'''
Allows to handle custom placeholders 'title_color' and 'message_no_color'.
To use this formatter, make sure to pass 'color', 'title' as log extras.
'''
class AutoGptFormatter(logging.Formatter):
"""
Allows to handle custom placeholders 'title_color' and 'message_no_color'.
To use this formatter, make sure to pass 'color', 'title' as log extras.
"""
def format(self, record: LogRecord) -> str:
if (hasattr(record, 'color')):
record.title_color = getattr(record, 'color') + getattr(record, 'title') + " " + Style.RESET_ALL
Expand Down
Loading

0 comments on commit 9b256a3

Please sign in to comment.