Skip to content

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.

Merge branch 'master' into dev

Andres Caicedo8e2074f48375
diff --cc .gitignore
index d47b839663,a4e3cc2d8e..6eecde953f
--- a/.gitignore
+++ b/.gitignore
@@@ -6,4 -6,5 +6,5 @@@ package-lock.jso
*.pyc
scripts/auto_gpt_workspace/*
*.mpeg
- venv/*
+ .env
-last_run_ai_settings.yaml
++last_run_ai_settings.yaml
diff --cc scripts/agent_manager.py
index b829b21900,ad120c4059..e6bf3b8632
--- a/scripts/agent_manager.py
+++ b/scripts/agent_manager.py
@@@ -4,10 -4,9 +4,10 @@@ next_key =
agents = {} # key, (task, full_message_history, model)
# 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
global agents
diff --cc scripts/ai_functions.py
index 6659bb5f00,05aa93a2da..eb524b9b7c
--- a/scripts/ai_functions.py
+++ b/scripts/ai_functions.py
@@@ -25,9 -7,7 +7,8 @@@ cfg = Config(
# Evaluating code
-
def evaluate_code(code: str) -> List[str]:
+ """Evaluates the given code and returns a list of suggestions for improvements."""
function_string = "def analyze_code(code: str) -> List[str]:"
args = [code]
description_string = """Analyzes the given code and returns a list of suggestions for improvements."""
@@@ -38,9 -19,7 +20,8 @@@
# Improving code
-
def improve_code(suggestions: List[str], code: str) -> str:
+ """Improves the provided code based on the suggestions provided, making no other changes."""
function_string = (
"def generate_improved_code(suggestions: List[str], code: str) -> str:"
)
diff --cc scripts/browse.py
index 74d01b809e,f096c5f3e2..8a10ddd603
--- a/scripts/browse.py
+++ b/scripts/browse.py
@@@ -1,12 -1,11 +1,12 @@@
- from googlesearch import search
import requests
from bs4 import BeautifulSoup
- from readability import Document
- import openai
+ from config import Config
+ from llm_utils import create_chat_completion
+ cfg = Config()
def scrape_text(url):
+ """Scrape text from a webpage"""
response = requests.get(url)
# Check if the response contains an HTTP error
diff --cc scripts/commands.py
index dbfe36c73d,2e332711bc..7a3633df9c
--- a/scripts/commands.py
+++ b/scripts/commands.py
@@@ -12,12 -14,21 +14,22 @@@ cfg = Config(
def get_command(response):
+ """Parse the response and return the command name and arguments"""
try:
- response_json = json.loads(response)
+ response_json = fix_and_parse_json(response)
+
+ if "command" not in response_json:
+ return "Error:" , "Missing 'command' object in JSON"
+
command = response_json["command"]
+
+ if "name" not in command:
+ return "Error:", "Missing 'name' field in 'command' object"
+
command_name = command["name"]
- arguments = command["args"]
+
+ # Use an empty dictionary if 'args' field is not present in 'command' object
+ arguments = command.get("args", {})
if not arguments:
arguments = {}
@@@ -101,9 -102,8 +105,9 @@@ def get_datetime()
def google_search(query, num_results=8):
+ """Return the results of a google search"""
search_results = []
- for j in browse.search(query, num_results=num_results):
+ for j in search(query, num_results=num_results):
search_results.append(j)
return json.dumps(search_results, ensure_ascii=False, indent=4)
@@@ -156,8 -151,7 +160,8 @@@ def delete_memory(key)
def overwrite_memory(key, string):
- """Overwrite a memory with a given key"""
- if key >= 0 and key < len(mem.permanent_memory):
++ """Overwrite a memory with a given key and string"""
+ if int(key) >= 0 and key < len(mem.permanent_memory):
_text = "Overwriting memory with key " + \
str(key) + " and string " + string
mem.permanent_memory[key] = string
@@@ -174,8 -167,7 +178,8 @@@ def shutdown()
quit()
- def start_agent(name, task, prompt, model="gpt-3.5-turbo"):
+ def start_agent(name, task, prompt, model=cfg.fast_llm_model):
+ """Start an agent with a given name, task, and prompt"""
global cfg
# Remove underscores from name
diff --cc scripts/config.py
index ac14565779,44d99bffd0..fa3bf7ccd2
--- a/scripts/config.py
+++ b/scripts/config.py
@@@ -20,14 -25,44 +26,47 @@@ class Config(metaclass=Singleton)
"""
def __init__(self):
+ """Initialize the configuration class."""
self.continuous_mode = False
self.speak_mode = False
+ # TODO - make these models be self-contained, using langchain, so we can configure them once and call it good
+ self.fast_llm_model = os.getenv("FAST_LLM_MODEL", "gpt-3.5-turbo")
+ self.smart_llm_model = os.getenv("SMART_LLM_MODEL", "gpt-4")
+ self.fast_token_limit = int(os.getenv("FAST_TOKEN_LIMIT", 4000))
+ self.smart_token_limit = int(os.getenv("SMART_TOKEN_LIMIT", 8000))
+
+ self.openai_api_key = os.getenv("OPENAI_API_KEY")
+ self.elevenlabs_api_key = os.getenv("ELEVENLABS_API_KEY")
+
+ # Initialize the OpenAI API client
+ openai.api_key = self.openai_api_key
+
def set_continuous_mode(self, value: bool):
+ """Set the continuous mode value."""
self.continuous_mode = value
def set_speak_mode(self, value: bool):
+ """Set the speak mode value."""
self.speak_mode = value
+
+ def set_fast_llm_model(self, value: str):
+ self.fast_llm_model = value
+
+ def set_smart_llm_model(self, value: str):
+ self.smart_llm_model = value
+
+ def set_fast_token_limit(self, value: int):
+ self.fast_token_limit = value
+
+ def set_smart_token_limit(self, value: int):
+ self.smart_token_limit = value
+
+ def set_openai_api_key(self, value: str):
+ self.apiopenai_api_key_key = value
+
+ def set_elevenlabs_api_key(self, value: str):
+ self.elevenlabs_api_key = value
+
+
+
diff --cc scripts/data.py
index b1faec8757,0a72cbbfc8..2239384453
--- a/scripts/data.py
+++ b/scripts/data.py
@@@ -1,8 -1,15 +1,16 @@@
+ import os
+ from pathlib import Path
+
+
def load_prompt():
+ """Load the prompt from data/prompt.txt"""
try:
+ # get directory of this file:
+ file_dir = Path(os.path.dirname(os.path.realpath(__file__)))
+ data_dir = file_dir / "data"
+ prompt_file = data_dir / "prompt.txt"
# Load the promt from data/prompt.txt
- with open("data/prompt.txt", "r") as prompt_file:
+ with open(prompt_file, "r") as prompt_file:
prompt = prompt_file.read()
return prompt
diff --cc scripts/execute_code.py
index 01b454a09f,614ef6fc3d..f34469dda8
--- a/scripts/execute_code.py
+++ b/scripts/execute_code.py
@@@ -3,9 -3,10 +3,11 @@@ import o
def execute_python_file(file):
+ """Execute a Python file in a Docker container and return the output"""
workspace_folder = "auto_gpt_workspace"
+ print (f"Executing file '{file}' in workspace '{workspace_folder}'")
+
if not file.endswith(".py"):
return "Error: Invalid file type. Only .py files are allowed."
diff --cc scripts/main.py
index 298fa95ccc,48093cf458..b4236c52a0
--- a/scripts/main.py
+++ b/scripts/main.py
@@@ -11,10 -11,12 +11,13 @@@ import spea
from enum import Enum, auto
import sys
from config import Config
-
+ from json_parser import fix_and_parse_json
+ from ai_config import AIConfig
+ import traceback
+ import yaml
class Argument(Enum):
+ """This class is used to define the different arguments that can be passed"""
CONTINUOUS_MODE = "continuous-mode"
SPEAK_MODE = "speak-mode"
@@@ -105,8 -168,35 +171,36 @@@ def load_variables(config_file="config.
def construct_prompt():
- """Constructs the prompt for the AI"""
++ """Construct the prompt for the AI to respond to"""
+ config = AIConfig.load()
+ if config.ai_name:
+ print_to_console(
+ f"Welcome back! ",
+ Fore.GREEN,
+ f"Would you like me to return to being {config.ai_name}?",
+ speak_text=True)
+ should_continue = input(f"""Continue with the last settings?
+ Name: {config.ai_name}
+ Role: {config.ai_role}
+ Goals: {config.ai_goals}
+ Continue (y/n): """)
+ if should_continue.lower() == "n":
+ config = AIConfig()
+
+ if not config.ai_name:
+ config = prompt_user()
+ config.save()
+
+ # Get rid of this global:
global ai_name
+ ai_name = config.ai_name
+
+ full_prompt = config.construct_full_prompt()
+ return full_prompt
+
+
+ def prompt_user():
+ ai_name = ""
# Construct the prompt
print_to_console(
"Welcome to Auto-GPT! ",
@@@ -154,22 -244,10 +248,11 @@@
ai_goals = ["Increase net worth", "Grow Twitter Account",
"Develop and manage multiple businesses autonomously"]
- prompt = data.load_prompt()
- prompt_start = """Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications."""
-
- # Construct full prompt
- full_prompt = f"You are {ai_name}, {ai_role}\n{prompt_start}\n\nGOALS:\n\n"
- for i, goal in enumerate(ai_goals):
- full_prompt += f"{i+1}. {goal}\n"
-
- full_prompt += f"\n\n{prompt}"
- return full_prompt
-
- # Check if the python script was executed with arguments, get those arguments
-
+ config = AIConfig(ai_name, ai_role, ai_goals)
+ return config
def parse_arguments():
+ """Parses the arguments passed to the script"""
global cfg
cfg.set_continuous_mode(False)
cfg.set_speak_mode(False)
diff --cc scripts/speak.py
index db05a024fe,2fbcbed26f..1e0eb4088a
--- a/scripts/speak.py
+++ b/scripts/speak.py
@@@ -7,12 -9,10 +9,11 @@@ voices = ["ErXwobaYiN019PkySvjV", "EXAV
tts_headers = {
"Content-Type": "application/json",
- "xi-api-key": keys.ELEVENLABS_API_KEY
+ "xi-api-key": cfg.elevenlabs_api_key
}
-
def say_text(text, voice_index=0):
+ """Say text using ElevenLabs API"""
tts_url = "https://api.elevenlabs.io/v1/text-to-speech/{voice_id}".format(
voice_id=voices[voice_index])