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.
Finish integrating command registry
BillSchumacherc110f3489dba
diff --git a/autogpt/__main__.py b/autogpt/__main__.pyindex 5fc9a1ead5..cd597506eb 100644--- a/autogpt/__main__.py+++ b/autogpt/__main__.py@@ -2,17 +2,17 @@import loggingimport osfrom pathlib import Path+from colorama import Fore+from autogpt.agent.agent import Agentfrom autogpt.args import parse_argumentsfrom autogpt.commands.command import CommandRegistryfrom autogpt.config import Config, check_openai_api_keyfrom autogpt.logs import loggerfrom autogpt.memory import get_memory--from autogpt.prompts.prompt import construct_main_ai_configfrom autogpt.plugins import load_plugins-+from autogpt.prompts.prompt import construct_main_ai_config# Load environment variables from .env file@@ -47,13 +47,20 @@ def main() -> None:cfg.set_plugins(loaded_plugins)# Create a CommandRegistry instance and scan default foldercommand_registry = CommandRegistry()- command_registry.import_commands("scripts.ai_functions")- command_registry.import_commands("scripts.commands")- command_registry.import_commands("scripts.execute_code")- command_registry.import_commands("scripts.agent_manager")- command_registry.import_commands("scripts.file_operations")+ command_registry.import_commands("autogpt.commands.audio_text")+ command_registry.import_commands("autogpt.commands.evaluate_code")+ command_registry.import_commands("autogpt.commands.execute_code")+ command_registry.import_commands("autogpt.commands.file_operations")+ command_registry.import_commands("autogpt.commands.git_operations")+ command_registry.import_commands("autogpt.commands.google_search")+ command_registry.import_commands("autogpt.commands.image_gen")+ command_registry.import_commands("autogpt.commands.twitter")+ command_registry.import_commands("autogpt.commands.web_selenium")+ command_registry.import_commands("autogpt.commands.write_tests")+ command_registry.import_commands("autogpt.app")ai_name = ""ai_config = construct_main_ai_config()+ ai_config.command_registry = command_registry# print(prompt)# Initialize variablesfull_message_history = []@@ -70,6 +77,9 @@ def main() -> None:f"Using memory of type:", Fore.GREEN, f"{memory.__class__.__name__}")logger.typewriter_log(f"Using Browser:", Fore.GREEN, cfg.selenium_web_browser)+ prompt = ai_config.construct_full_prompt()+ if cfg.debug_mode:+ logger.typewriter_log("Prompt:", Fore.GREEN, prompt)agent = Agent(ai_name=ai_name,memory=memory,@@ -77,7 +87,7 @@ def main() -> None:next_action_count=next_action_count,command_registry=command_registry,config=ai_config,- prompt=ai_config.construct_full_prompt(),+ prompt=prompt,user_input=user_input,)agent.start_interaction_loop()diff --git a/autogpt/agent/agent.py b/autogpt/agent/agent.pyindex 513478b9d8..8117818ea4 100644--- a/autogpt/agent/agent.py+++ b/autogpt/agent/agent.py@@ -1,6 +1,6 @@from colorama import Fore, Style-from autogpt.app import execute_command, get_command+from autogpt.app import execute_command, get_commandfrom autogpt.chat import chat_with_ai, create_chat_messagefrom autogpt.config import Configfrom autogpt.json_fixes.bracket_termination import (diff --git a/autogpt/agent/agent_manager.py b/autogpt/agent/agent_manager.pyindex e848bfe77c..e1353e03a5 100644--- a/autogpt/agent/agent_manager.py+++ b/autogpt/agent/agent_manager.py@@ -1,8 +1,8 @@"""Agent manager for managing GPT agents"""from __future__ import annotations+from autogpt.config.config import Config, Singletonfrom autogpt.llm_utils import create_chat_completion-from autogpt.config.config import Singleton, Configclass AgentManager(metaclass=Singleton):diff --git a/autogpt/app.py b/autogpt/app.pyindex 1e78262662..3a8bbc2a9a 100644--- a/autogpt/app.py+++ b/autogpt/app.py@@ -1,16 +1,11 @@""" Command and Control """import jsonfrom typing import List, NoReturn, Union+from autogpt.agent.agent_manager import AgentManager-from autogpt.commands.command import command, CommandRegistry-from autogpt.commands.evaluate_code import evaluate_code-from autogpt.commands.google_search import google_official_search, google_search-from autogpt.commands.improve_code import improve_code-from autogpt.commands.write_tests import write_tests-from autogpt.config import Config-from autogpt.commands.image_gen import generate_imagefrom autogpt.commands.audio_text import read_audio_from_file-from autogpt.commands.web_requests import scrape_links, scrape_text+from autogpt.commands.command import CommandRegistry, command+from autogpt.commands.evaluate_code import evaluate_codefrom autogpt.commands.execute_code import execute_python_file, execute_shellfrom autogpt.commands.file_operations import (append_to_file,@@ -19,15 +14,20 @@ from autogpt.commands.file_operations import (search_files,write_to_file,)+from autogpt.commands.git_operations import clone_repository+from autogpt.commands.google_search import google_official_search, google_search+from autogpt.commands.image_gen import generate_image+from autogpt.commands.improve_code import improve_code+from autogpt.commands.twitter import send_tweet+from autogpt.commands.web_requests import scrape_links, scrape_text+from autogpt.commands.web_selenium import browse_website+from autogpt.commands.write_tests import write_tests+from autogpt.config import Configfrom autogpt.json_fixes.parsing import fix_and_parse_jsonfrom autogpt.memory import get_memoryfrom autogpt.processing.text import summarize_textfrom autogpt.prompts.generator import PromptGeneratorfrom autogpt.speech import say_text-from autogpt.commands.web_selenium import browse_website-from autogpt.commands.git_operations import clone_repository-from autogpt.commands.twitter import send_tweet-CFG = Config()AGENT_MANAGER = AgentManager()@@ -132,76 +132,16 @@ def execute_command(# TODO: Remove commands below after they are moved to the command registry.command_name = map_command_synonyms(command_name)- if command_name == "google":- # Check if the Google API key is set and use the official search method- # If the API key is not set or has only whitespaces, use the unofficial- # search method- key = CFG.google_api_key- if key and key.strip() and key != "your-google-api-key":- google_result = google_official_search(arguments["input"])- return google_result- else:- google_result = google_search(arguments["input"])-- # google_result can be a list or a string depending on the search results- if isinstance(google_result, list):- safe_message = [- google_result_single.encode("utf-8", "ignore")- for google_result_single in google_result- ]- else:- safe_message = google_result.encode("utf-8", "ignore")-- return str(safe_message)- elif command_name == "memory_add":++ if command_name == "memory_add":return memory.add(arguments["string"])- elif command_name == "start_agent":- return start_agent(- arguments["name"], arguments["task"], arguments["prompt"]- )- elif command_name == "message_agent":- return message_agent(arguments["key"], arguments["message"])- elif command_name == "list_agents":- return list_agents()- elif command_name == "delete_agent":- return delete_agent(arguments["key"])elif command_name == "get_text_summary":return get_text_summary(arguments["url"], arguments["question"])elif command_name == "get_hyperlinks":return get_hyperlinks(arguments["url"])- elif command_name == "clone_repository":- return clone_repository(- arguments["repository_url"], arguments["clone_path"]- )- elif command_name == "read_file":- return read_file(arguments["file"])- elif command_name == "write_to_file":- return write_to_file(arguments["file"], arguments["text"])- elif command_name == "append_to_file":- return append_to_file(arguments["file"], arguments["text"])- elif command_name == "delete_file":- return delete_file(arguments["file"])- elif command_name == "search_files":- return search_files(arguments["directory"])- elif command_name == "browse_website":- return browse_website(arguments["url"], arguments["question"])# TODO: Change these to take in a file rather than pasted code, if# non-file is given, return instructions "Input should be a python- # filepath, write your code to file and try again"- elif command_name == "evaluate_code":- return evaluate_code(arguments["code"])- elif command_name == "improve_code":- return improve_code(arguments["suggestions"], arguments["code"])- elif command_name == "write_tests":- return write_tests(arguments["code"], arguments.get("focus"))- elif command_name == "execute_python_file": # Add this command- return execute_python_file(arguments["file"])- elif command_name == "read_audio_from_file":- return read_audio_from_file(arguments["file"])- elif command_name == "generate_image":- return generate_image(arguments["prompt"])- elif command_name == "send_tweet":- return send_tweet(arguments["text"])+ # filepath, write your code to file and try againelif command_name == "do_nothing":return "No action performed."elif command_name == "task_complete":@@ -305,7 +245,7 @@ def message_agent(key: str, message: str) -> str:@command("list_agents", "List GPT Agents", "")-def list_agents():+def list_agents() -> str:"""List all agentsReturns:diff --git a/autogpt/args.py b/autogpt/args.pyindex eca3233472..20d25a4c4c 100644--- a/autogpt/args.py+++ b/autogpt/args.py@@ -2,6 +2,7 @@import argparsefrom colorama import Fore+from autogpt import utilsfrom autogpt.config import Configfrom autogpt.logs import loggerdiff --git a/autogpt/commands/audio_text.py b/autogpt/commands/audio_text.pyindex 84819d5ed7..421a1f18ee 100644--- a/autogpt/commands/audio_text.py+++ b/autogpt/commands/audio_text.py@@ -1,23 +1,51 @@-import requests+"""Commands for converting audio to text."""import json+import requests++from autogpt.commands.command import commandfrom autogpt.config import Configfrom autogpt.workspace import path_in_workspace-cfg = Config()+CFG = Config()++@command(+ "read_audio_from_file",+ "Convert Audio to text",+ '"file": "<file>"',+ CFG.huggingface_audio_to_text_model,+ "Configure huggingface_audio_to_text_model.",+)+def read_audio_from_file(audio_path: str) -> str:+ """+ Convert audio to text.-def read_audio_from_file(audio_path):+ Args:+ audio_path (str): The path to the audio file++ Returns:+ str: The text from the audio+ """audio_path = path_in_workspace(audio_path)with open(audio_path, "rb") as audio_file:audio = audio_file.read()return read_audio(audio)-def read_audio(audio):- model = cfg.huggingface_audio_to_text_model+def read_audio(audio: bytes) -> str:+ """+ Convert audio to text.++ Args:+ audio (bytes): The audio to convert++ Returns:+ str: The text from the audio+ """+ model = CFG.huggingface_audio_to_text_modelapi_url = f"https://api-inference.huggingface.co/models/{model}"- api_token = cfg.huggingface_api_token+ api_token = CFG.huggingface_api_tokenheaders = {"Authorization": f"Bearer {api_token}"}if api_token is None:@@ -32,4 +60,4 @@ def read_audio(audio):)text = json.loads(response.content.decode("utf-8"))["text"]- return "The audio says: " + text+ return f"The audio says: {text}"diff --git a/autogpt/commands/command.py b/autogpt/commands/command.pyindex d1dfc8fde6..3b3ccf51c2 100644--- a/autogpt/commands/command.py+++ b/autogpt/commands/command.py@@ -1,8 +1,8 @@-import os-import sysimport importlibimport inspect-from typing import Callable, Any, List, Optional+import os+import sys+from typing import Any, Callable, List, Optional# Unique identifier for auto-gpt commandsAUTO_GPT_COMMAND_IDENTIFIER = "auto_gpt_command"diff --git a/autogpt/commands/evaluate_code.py b/autogpt/commands/evaluate_code.pyindex 1c9b117dda..064e4512be 100644--- a/autogpt/commands/evaluate_code.py+++ b/autogpt/commands/evaluate_code.py@@ -5,7 +5,7 @@ from autogpt.commands.command import commandfrom autogpt.llm_utils import call_ai_function-@command("evaluate_code", "Evaluate Code", '"code": "<full _code_string>"')+@command("evaluate_code", "Evaluate Code", '"code": "<full_code_string>"')def evaluate_code(code: str) -> list[str]:"""A function that takes in a string and returns a response from create chatdiff --git a/autogpt/commands/execute_code.py b/autogpt/commands/execute_code.pyindex aa8a354552..b67707279a 100644--- a/autogpt/commands/execute_code.py+++ b/autogpt/commands/execute_code.py@@ -4,9 +4,10 @@ import subprocessimport dockerfrom docker.errors import ImageNotFound-from autogpt.config import Config+from autogpt.commands.command import command-from autogpt.workspace import path_in_workspace, WORKSPACE_PATH+from autogpt.config import Config+from autogpt.workspace import WORKSPACE_PATH, path_in_workspaceCFG = Config()diff --git a/autogpt/commands/file_operations.py b/autogpt/commands/file_operations.pyindex fea62fad18..4d8d76b311 100644--- a/autogpt/commands/file_operations.py+++ b/autogpt/commands/file_operations.py@@ -5,8 +5,9 @@ import osimport os.pathfrom pathlib import Pathfrom typing import Generator+from autogpt.commands.command import command-from autogpt.workspace import path_in_workspace, WORKSPACE_PATH+from autogpt.workspace import WORKSPACE_PATH, path_in_workspaceLOG_FILE = "file_logger.txt"LOG_FILE_PATH = WORKSPACE_PATH / LOG_FILEdiff --git a/autogpt/commands/git_operations.py b/autogpt/commands/git_operations.pyindex 3ff35cf31a..f5954032d4 100644--- a/autogpt/commands/git_operations.py+++ b/autogpt/commands/git_operations.py@@ -1,10 +1,19 @@"""Git operations for autogpt"""-import git+from git.repo import Repo++from autogpt.commands.command import commandfrom autogpt.config import ConfigCFG = Config()+@command(+ "clone_repository",+ "Clone Repositoryy",+ '"repository_url": "<url>", "clone_path": "<directory>"',+ CFG.github_username and CFG.github_api_key,+ "Configure github_username and github_api_key.",+)def clone_repository(repo_url: str, clone_path: str) -> str:"""Clone a github repository locally@@ -17,7 +26,7 @@ def clone_repository(repo_url: str, clone_path: str) -> str:split_url = repo_url.split("//")auth_repo_url = f"//{CFG.github_username}:{CFG.github_api_key}@".join(split_url)try:- git.Repo.clone_from(auth_repo_url, clone_path)+ Repo.clone_from(auth_repo_url, clone_path)return f"""Cloned {repo_url} to {clone_path}"""except Exception as e:return f"Error: {str(e)}"diff --git a/autogpt/commands/google_search.py b/autogpt/commands/google_search.pyindex 148ba1d0e1..0f635bcadc 100644--- a/autogpt/commands/google_search.py+++ b/autogpt/commands/google_search.py@@ -5,11 +5,13 @@ import jsonfrom duckduckgo_search import ddg+from autogpt.commands.command import commandfrom autogpt.config import ConfigCFG = Config()+@command("google", "Google Search", '"input": "<search>"', not CFG.google_api_key)def google_search(query: str, num_results: int = 8) -> str:"""Return the results of a google search@@ -31,9 +33,17 @@ def google_search(query: str, num_results: int = 8) -> str:for j in results:search_results.append(j)- return json.dumps(search_results, ensure_ascii=False, indent=4)+ results = json.dumps(search_results, ensure_ascii=False, indent=4)+ return safe_google_results(results)+@command(+ "google",+ "Google Search",+ '"input": "<search>"',+ bool(CFG.google_api_key),+ "Configure google_api_key.",+)def google_official_search(query: str, num_results: int = 8) -> str | list[str]:"""Return the results of a google search using the official Google API@@ -82,6 +92,26 @@ def google_official_search(query: str, num_results: int = 8) -> str | list[str]:return "Error: The provided Google API key is invalid or missing."else:return f"Error: {e}"+ # google_result can be a list or a string depending on the search results# Return the list of search result URLs- return search_results_links+ return safe_google_results(search_results_links)+++def safe_google_results(results: str | list) -> str:+ """+ Return the results of a google search in a safe format.++ Args:+ results (str | list): The search results.++ Returns:+ str: The results of the search.+ """+ if isinstance(results, list):+ safe_message = json.dumps(+ [result.enocde("utf-8", "ignore") for result in results]+ )+ else:+ safe_message = results.encode("utf-8", "ignore").decode("utf-8")+ return safe_messagediff --git a/autogpt/commands/image_gen.py b/autogpt/commands/image_gen.pyindex 2b62aa354b..9dbb2fa586 100644--- a/autogpt/commands/image_gen.py+++ b/autogpt/commands/image_gen.py@@ -1,12 +1,12 @@""" Image Generation Module for AutoGPT."""import io-import os.pathimport uuidfrom base64 import b64decodeimport openaiimport requestsfrom PIL import Image+from autogpt.commands.command import commandfrom autogpt.config import Configfrom autogpt.workspace import path_in_workspacediff --git a/autogpt/commands/improve_code.py b/autogpt/commands/improve_code.pyindex 0bfe725305..41a369b4db 100644--- a/autogpt/commands/improve_code.py+++ b/autogpt/commands/improve_code.py@@ -2,7 +2,7 @@ from __future__ import annotationsimport json-from autogpt.commands import command+from autogpt.commands.command import commandfrom autogpt.llm_utils import call_ai_functiondiff --git a/autogpt/commands/twitter.py b/autogpt/commands/twitter.pyindex dc4d450c1f..8e64b21357 100644--- a/autogpt/commands/twitter.py+++ b/autogpt/commands/twitter.py@@ -1,11 +1,30 @@-import tweepy+"""A module that contains a command to send a tweet."""import os++import tweepyfrom dotenv import load_dotenv+from autogpt.commands.command import command+load_dotenv()-def send_tweet(tweet_text):+@command(+ "send_tweet",+ "Send Tweet",+ '"text": "<text>"',+)+def send_tweet(tweet_text: str) -> str:+ """+ A function that takes in a string and returns a response from create chat+ completion api call.++ Args:+ tweet_text (str): Text to be tweeted.++ Returns:+ A result from sending the tweet.+ """consumer_key = os.environ.get("TW_CONSUMER_KEY")consumer_secret = os.environ.get("TW_CONSUMER_SECRET")access_token = os.environ.get("TW_ACCESS_TOKEN")@@ -20,6 +39,6 @@ def send_tweet(tweet_text):# Send tweettry:api.update_status(tweet_text)- print("Tweet sent successfully!")+ return "Tweet sent successfully!"except tweepy.TweepyException as e:- print("Error sending tweet: {}".format(e.reason))+ return f"Error sending tweet: {e.reason}"diff --git a/autogpt/commands/web_playwright.py b/autogpt/commands/web_playwright.pyindex a1abb6cb73..4e388ded20 100644--- a/autogpt/commands/web_playwright.py+++ b/autogpt/commands/web_playwright.py@@ -8,6 +8,7 @@ except ImportError:"Playwright not installed. Please install it with 'pip install playwright' to use.")from bs4 import BeautifulSoup+from autogpt.processing.html import extract_hyperlinks, format_hyperlinksdiff --git a/autogpt/commands/web_requests.py b/autogpt/commands/web_requests.pyindex 50d8d383cb..7613e5bd1d 100644--- a/autogpt/commands/web_requests.py+++ b/autogpt/commands/web_requests.py@@ -4,9 +4,9 @@ from __future__ import annotationsfrom urllib.parse import urljoin, urlparseimport requests-from requests.compat import urljoin-from requests import Responsefrom bs4 import BeautifulSoup+from requests import Response+from requests.compat import urljoinfrom autogpt.config import Configfrom autogpt.memory import get_memorydiff --git a/autogpt/commands/web_selenium.py b/autogpt/commands/web_selenium.pyindex 591d3162a3..ed79d56ce2 100644--- a/autogpt/commands/web_selenium.py+++ b/autogpt/commands/web_selenium.py@@ -1,22 +1,25 @@"""Selenium web scraping module."""from __future__ import annotations-from selenium import webdriver-from autogpt.processing.html import extract_hyperlinks, format_hyperlinks-import autogpt.processing.text as summary+import logging+from pathlib import Path+from bs4 import BeautifulSoup-from selenium.webdriver.remote.webdriver import WebDriver+from selenium import webdriver+from selenium.webdriver.chrome.options import Options as ChromeOptionsfrom selenium.webdriver.common.by import By-from selenium.webdriver.support.wait import WebDriverWait+from selenium.webdriver.firefox.options import Options as FirefoxOptions+from selenium.webdriver.remote.webdriver import WebDriver+from selenium.webdriver.safari.options import Options as SafariOptionsfrom selenium.webdriver.support import expected_conditions as EC+from selenium.webdriver.support.wait import WebDriverWaitfrom webdriver_manager.chrome import ChromeDriverManagerfrom webdriver_manager.firefox import GeckoDriverManager-from selenium.webdriver.chrome.options import Options as ChromeOptions-from selenium.webdriver.firefox.options import Options as FirefoxOptions-from selenium.webdriver.safari.options import Options as SafariOptions-import logging-from pathlib import Path++from autogpt.commands.command import command+import autogpt.processing.text as summaryfrom autogpt.config import Config+from autogpt.processing.html import extract_hyperlinks, format_hyperlinksFILE_DIR = Path(__file__).parent.parentCFG = Config()diff --git a/autogpt/commands/write_tests.py b/autogpt/commands/write_tests.pyindex 23d4c13000..91cd930429 100644--- a/autogpt/commands/write_tests.py+++ b/autogpt/commands/write_tests.py@@ -2,7 +2,8 @@from __future__ import annotationsimport json-from autogpt.commands import command++from autogpt.commands.command import commandfrom autogpt.llm_utils import call_ai_functiondiff --git a/autogpt/config/__init__.py b/autogpt/config/__init__.pyindex ceb5566ce7..726b6dcf3d 100644--- a/autogpt/config/__init__.py+++ b/autogpt/config/__init__.py@@ -2,7 +2,7 @@This module contains the configuration classes for AutoGPT."""from autogpt.config.ai_config import AIConfig-from autogpt.config.config import check_openai_api_key, Config+from autogpt.config.config import Config, check_openai_api_keyfrom autogpt.config.singleton import AbstractSingleton, Singleton__all__ = [diff --git a/autogpt/config/ai_config.py b/autogpt/config/ai_config.pyindex d18c75ba7d..c9022773fb 100644--- a/autogpt/config/ai_config.py+++ b/autogpt/config/ai_config.py@@ -6,7 +6,8 @@ from __future__ import annotationsimport osfrom pathlib import Path-from typing import Type+from typing import Optional, Type+import yamlfrom autogpt.prompts.generator import PromptGenerator@@ -41,6 +42,7 @@ class AIConfig:self.ai_role = ai_roleself.ai_goals = ai_goalsself.prompt_generator = None+ self.command_registry = None# Soon this will go in a folder where it remembers more stuff about the run(s)SAVE_FILE = Path(os.getcwd()) / "ai_settings.yaml"@@ -113,8 +115,8 @@ class AIConfig:"")- from autogpt.prompts.prompt import build_default_prompt_generatorfrom autogpt.config import Config+ from autogpt.prompts.prompt import build_default_prompt_generatorcfg = Config()if prompt_generator is None:@@ -122,6 +124,7 @@ class AIConfig:prompt_generator.goals = self.ai_goalsprompt_generator.name = self.ai_nameprompt_generator.role = self.ai_role+ prompt_generator.command_registry = self.command_registryfor plugin in cfg.plugins:prompt_generator = plugin.post_prompt(prompt_generator)diff --git a/autogpt/config/config.py b/autogpt/config/config.pyindex 46ab95d8d4..a5cd07101f 100644--- a/autogpt/config/config.py+++ b/autogpt/config/config.py@@ -1,14 +1,13 @@"""Configuration class to store the state of bools for different scripts access."""import os-from colorama import Fore--from autogpt.config.singleton import Singletonimport openaiimport yaml-+from colorama import Forefrom dotenv import load_dotenv+from autogpt.config.singleton import Singleton+load_dotenv(verbose=True)diff --git a/autogpt/data_ingestion.py b/autogpt/data_ingestion.pyindex 01bafc2ad0..b89a33dafd 100644--- a/autogpt/data_ingestion.py+++ b/autogpt/data_ingestion.py@@ -1,8 +1,8 @@import argparseimport logging-from autogpt.config import Configfrom autogpt.commands.file_operations import ingest_file, search_files+from autogpt.config import Configfrom autogpt.memory import get_memorycfg = Config()diff --git a/autogpt/json_fixes/auto_fix.py b/autogpt/json_fixes/auto_fix.pyindex 9fcf909a49..8ad458ab97 100644--- a/autogpt/json_fixes/auto_fix.py+++ b/autogpt/json_fixes/auto_fix.py@@ -1,9 +1,9 @@"""This module contains the function to fix JSON strings using GPT-3."""import json+from autogpt.config import Configfrom autogpt.llm_utils import call_ai_functionfrom autogpt.logs import logger-from autogpt.config import ConfigCFG = Config()diff --git a/autogpt/json_fixes/bracket_termination.py b/autogpt/json_fixes/bracket_termination.pyindex 822eed4a54..260301dc25 100644--- a/autogpt/json_fixes/bracket_termination.py+++ b/autogpt/json_fixes/bracket_termination.py@@ -3,11 +3,12 @@ from __future__ import annotationsimport contextlibimport json+import regexfrom colorama import Fore-from autogpt.logs import loggerfrom autogpt.config import Config+from autogpt.logs import loggerfrom autogpt.speech import say_textCFG = Config()diff --git a/autogpt/llm_utils.py b/autogpt/llm_utils.pyindex 559820ed8d..701d622b54 100644--- a/autogpt/llm_utils.py+++ b/autogpt/llm_utils.py@@ -1,11 +1,11 @@from __future__ import annotations-from ast import Listimport time+from ast import Listimport openai-from openai.error import APIError, RateLimitErrorfrom colorama import Fore+from openai.error import APIError, RateLimitErrorfrom autogpt.config import Configdiff --git a/autogpt/logs.py b/autogpt/logs.pyindex 22ce23f4aa..f5c6fa8177 100644--- a/autogpt/logs.py+++ b/autogpt/logs.py@@ -5,13 +5,13 @@ import osimport randomimport reimport time-from logging import LogRecordimport traceback+from logging import LogRecordfrom colorama import Fore, Style-from autogpt.speech import say_textfrom autogpt.config import Config, Singleton+from autogpt.speech import say_textCFG = Config()diff --git a/autogpt/memory/local.py b/autogpt/memory/local.pyindex 6c7ee1b36a..998b5f1d94 100644--- a/autogpt/memory/local.py+++ b/autogpt/memory/local.py@@ -7,8 +7,8 @@ from typing import Anyimport numpy as npimport orjson-from autogpt.memory.base import MemoryProviderSingletonfrom autogpt.llm_utils import create_embedding_with_ada+from autogpt.memory.base import MemoryProviderSingletonEMBED_DIM = 1536SAVE_OPTIONS = orjson.OPT_SERIALIZE_NUMPY | orjson.OPT_SERIALIZE_DATACLASSdiff --git a/autogpt/memory/milvus.py b/autogpt/memory/milvus.pyindex c6e7d5a372..93aa8b15d6 100644--- a/autogpt/memory/milvus.py+++ b/autogpt/memory/milvus.py@@ -1,11 +1,5 @@""" Milvus memory storage provider."""-from pymilvus import (- connections,- FieldSchema,- CollectionSchema,- DataType,- Collection,-)+from pymilvus import Collection, CollectionSchema, DataType, FieldSchema, connectionsfrom autogpt.memory.base import MemoryProviderSingleton, get_ada_embeddingdiff --git a/autogpt/memory/pinecone.py b/autogpt/memory/pinecone.pyindex d781073e3f..27fcd62482 100644--- a/autogpt/memory/pinecone.py+++ b/autogpt/memory/pinecone.py@@ -1,9 +1,9 @@import pineconefrom colorama import Fore, Style+from autogpt.llm_utils import create_embedding_with_adafrom autogpt.logs import loggerfrom autogpt.memory.base import MemoryProviderSingleton-from autogpt.llm_utils import create_embedding_with_adaclass PineconeMemory(MemoryProviderSingleton):diff --git a/autogpt/memory/redismem.py b/autogpt/memory/redismem.pyindex 0e8dd71d91..082a812c53 100644--- a/autogpt/memory/redismem.py+++ b/autogpt/memory/redismem.py@@ -10,9 +10,9 @@ from redis.commands.search.field import TextField, VectorFieldfrom redis.commands.search.indexDefinition import IndexDefinition, IndexTypefrom redis.commands.search.query import Query+from autogpt.llm_utils import create_embedding_with_adafrom autogpt.logs import loggerfrom autogpt.memory.base import MemoryProviderSingleton-from autogpt.llm_utils import create_embedding_with_adaSCHEMA = [TextField("data"),diff --git a/autogpt/memory/weaviate.py b/autogpt/memory/weaviate.pyindex 19035381f3..ef0e34760e 100644--- a/autogpt/memory/weaviate.py+++ b/autogpt/memory/weaviate.py@@ -1,11 +1,13 @@-from autogpt.config import Config-from autogpt.memory.base import MemoryProviderSingleton, get_ada_embeddingimport uuid+import weaviatefrom weaviate import Clientfrom weaviate.embedded import EmbeddedOptionsfrom weaviate.util import generate_uuid5+from autogpt.config import Config+from autogpt.memory.base import MemoryProviderSingleton, get_ada_embedding+def default_schema(weaviate_index):return {diff --git a/autogpt/plugins.py b/autogpt/plugins.pyindex 7b843a6ac1..a00b989eae 100644--- a/autogpt/plugins.py+++ b/autogpt/plugins.py@@ -1,10 +1,10 @@"""Handles loading of plugins."""-from ast import Moduleimport zipfile+from ast import Modulefrom pathlib import Path-from zipimport import zipimporterfrom typing import List, Optional, Tuple+from zipimport import zipimporterdef inspect_zip_for_module(zip_path: str, debug: bool = False) -> Optional[str]:diff --git a/autogpt/processing/html.py b/autogpt/processing/html.pyindex e1912b6ad4..81387b12ad 100644--- a/autogpt/processing/html.py+++ b/autogpt/processing/html.py@@ -1,8 +1,8 @@"""HTML processing functions"""from __future__ import annotations-from requests.compat import urljoinfrom bs4 import BeautifulSoup+from requests.compat import urljoindef extract_hyperlinks(soup: BeautifulSoup, base_url: str) -> list[tuple[str, str]]:diff --git a/autogpt/processing/text.py b/autogpt/processing/text.pyindex d30036d878..84e6a1dea6 100644--- a/autogpt/processing/text.py+++ b/autogpt/processing/text.py@@ -1,9 +1,11 @@"""Text processing functions"""-from typing import Generator, Optional, Dict+from typing import Dict, Generator, Optional+from selenium.webdriver.remote.webdriver import WebDriver-from autogpt.memory import get_memory+from autogpt.config import Configfrom autogpt.llm_utils import create_chat_completion+from autogpt.memory import get_memoryCFG = Config()MEMORY = get_memory(CFG)diff --git a/autogpt/prompts/generator.py b/autogpt/prompts/generator.pyindex f8a37b85e7..24768203d5 100644--- a/autogpt/prompts/generator.py+++ b/autogpt/prompts/generator.py@@ -19,6 +19,7 @@ class PromptGenerator:self.resources = []self.performance_evaluation = []self.goals = []+ self.command_registry = Noneself.name = "Bob"self.role = "AI"self.response_format = {@@ -119,10 +120,14 @@ class PromptGenerator:str: The formatted numbered list."""if item_type == "command":- return "\n".join(- f"{i+1}. {self._generate_command_string(item)}"- for i, item in enumerate(items)- )+ command_strings = []+ if self.command_registry:+ command_strings += [+ str(item) for item in self.command_registry.commands.values()+ ]+ # These are the commands that are added manually, do_nothing and terminate+ command_strings += [self._generate_command_string(item) for item in items]+ return "\n".join(f"{i+1}. {item}" for i, item in enumerate(command_strings))else:return "\n".join(f"{i+1}. {item}" for i, item in enumerate(items))diff --git a/autogpt/prompts/prompt.py b/autogpt/prompts/prompt.pyindex d82cdb16ae..ba04263e05 100644--- a/autogpt/prompts/prompt.py+++ b/autogpt/prompts/prompt.py@@ -1,4 +1,5 @@from colorama import Fore+from autogpt.config.ai_config import AIConfigfrom autogpt.config.config import Configfrom autogpt.logs import logger@@ -37,63 +38,9 @@ def build_default_prompt_generator() -> PromptGenerator:# Define the command listcommands = [- ("Google Search", "google", {"input": "<search>"}),- (- "Browse Website",- "browse_website",- {"url": "<url>", "question": "<what_you_want_to_find_on_website>"},- ),- (- "Start GPT Agent",- "start_agent",- {"name": "<name>", "task": "<short_task_desc>", "prompt": "<prompt>"},- ),- (- "Message GPT Agent",- "message_agent",- {"key": "<key>", "message": "<message>"},- ),- ("List GPT Agents", "list_agents", {}),- ("Delete GPT Agent", "delete_agent", {"key": "<key>"}),- (- "Clone Repository",- "clone_repository",- {"repository_url": "<url>", "clone_path": "<directory>"},- ),- ("Write to file", "write_to_file", {"file": "<file>", "text": "<text>"}),- ("Read file", "read_file", {"file": "<file>"}),- ("Append to file", "append_to_file", {"file": "<file>", "text": "<text>"}),- ("Delete file", "delete_file", {"file": "<file>"}),- ("Search Files", "search_files", {"directory": "<directory>"}),- ("Evaluate Code", "evaluate_code", {"code": "<full_code_string>"}),- (- "Get Improved Code",- "improve_code",- {"suggestions": "<list_of_suggestions>", "code": "<full_code_string>"},- ),- (- "Write Tests",- "write_tests",- {"code": "<full_code_string>", "focus": "<list_of_focus_areas>"},- ),- ("Execute Python File", "execute_python_file", {"file": "<file>"}),- ("Generate Image", "generate_image", {"prompt": "<prompt>"}),- ("Send Tweet", "send_tweet", {"text": "<text>"}),- ]-- # Only add the audio to text command if the model is specified- if cfg.huggingface_audio_to_text_model:- commands.append(- ("Convert Audio to text", "read_audio_from_file", {"file": "<file>"}),- )-- # Add these command last.- commands.append(("Do Nothing", "do_nothing", {}),- )- commands.append(("Task Complete (Shutdown)", "task_complete", {"reason": "<reason>"}),- )+ ]# Add commands to the PromptGenerator objectfor command_label, command_name, args in commands:diff --git a/autogpt/setup.py b/autogpt/setup.pyindex 5315c01db0..d719688dc6 100644--- a/autogpt/setup.py+++ b/autogpt/setup.py@@ -1,5 +1,6 @@"""Setup the AI and its goals"""from colorama import Fore, Style+from autogpt import utilsfrom autogpt.config.ai_config import AIConfigfrom autogpt.logs import loggerdiff --git a/autogpt/speech/brian.py b/autogpt/speech/brian.pyindex e581bbcc8d..3cc593c216 100644--- a/autogpt/speech/brian.py+++ b/autogpt/speech/brian.py@@ -1,5 +1,6 @@""" Brian speech module for autogpt """import os+import requestsfrom playsound import playsounddiff --git a/autogpt/speech/eleven_labs.py b/autogpt/speech/eleven_labs.pyindex 0af48cae15..a9b30dbbc3 100644--- a/autogpt/speech/eleven_labs.py+++ b/autogpt/speech/eleven_labs.py@@ -1,8 +1,8 @@"""ElevenLabs speech module"""import os-from playsound import playsoundimport requests+from playsound import playsoundfrom autogpt.config import Configfrom autogpt.speech.base import VoiceBasediff --git a/autogpt/speech/gtts.py b/autogpt/speech/gtts.pyindex 37497075e7..1c3e9cae05 100644--- a/autogpt/speech/gtts.py+++ b/autogpt/speech/gtts.py@@ -1,7 +1,8 @@""" GTTS Voice. """import os-from playsound import playsound+import gtts+from playsound import playsoundfrom autogpt.speech.base import VoiceBasediff --git a/autogpt/speech/say.py b/autogpt/speech/say.pyindex 78b75b21fc..727983d12b 100644--- a/autogpt/speech/say.py+++ b/autogpt/speech/say.py@@ -1,13 +1,12 @@""" Text to speech module """-from autogpt.config import Config-import threadingfrom threading import Semaphore++from autogpt.config import Configfrom autogpt.speech.brian import BrianSpeech-from autogpt.speech.macos_tts import MacOSTTS-from autogpt.speech.gtts import GTTSVoicefrom autogpt.speech.eleven_labs import ElevenLabsSpeech-+from autogpt.speech.gtts import GTTSVoice+from autogpt.speech.macos_tts import MacOSTTSCFG = Config()DEFAULT_VOICE_ENGINE = GTTSVoice()diff --git a/scripts/check_requirements.py b/scripts/check_requirements.pyindex d1f2350413..e4eab024a6 100644--- a/scripts/check_requirements.py+++ b/scripts/check_requirements.py@@ -1,6 +1,7 @@-import pkg_resourcesimport sys+import pkg_resources+def main():requirements_file = sys.argv[1]diff --git a/tests.py b/tests.pyindex 67ba1c8eb1..62f76da8ac 100644--- a/tests.py+++ b/tests.py@@ -1,4 +1,5 @@import unittest+import coverageif __name__ == "__main__":diff --git a/tests/browse_tests.py b/tests/browse_tests.pyindex 1ac523ecdc..f896e7dd75 100644--- a/tests/browse_tests.py+++ b/tests/browse_tests.py@@ -1,6 +1,6 @@-import unittestimport osimport sys+import unittestfrom bs4 import BeautifulSoupdiff --git a/tests/integration/weaviate_memory_tests.py b/tests/integration/weaviate_memory_tests.pyindex 6f3edd99f6..ce4c63da3d 100644--- a/tests/integration/weaviate_memory_tests.py+++ b/tests/integration/weaviate_memory_tests.py@@ -1,15 +1,15 @@+import os+import sysimport unittestfrom unittest import mock-import sys-import os+from uuid import uuid4from weaviate import Clientfrom weaviate.util import get_valid_uuid-from uuid import uuid4from autogpt.config import Config-from autogpt.memory.weaviate import WeaviateMemoryfrom autogpt.memory.base import get_ada_embedding+from autogpt.memory.weaviate import WeaviateMemory@mock.patch.dict(diff --git a/tests/test_commands.py b/tests/test_commands.pyindex a21bbb4dc2..49c09f11db 100644--- a/tests/test_commands.py+++ b/tests/test_commands.py@@ -3,6 +3,7 @@ import sysfrom pathlib import Pathimport pytest+from autogpt.commands.command import Command, CommandRegistrydiff --git a/tests/test_token_counter.py b/tests/test_token_counter.pyindex 81e68277fd..6d7ae016b2 100644--- a/tests/test_token_counter.py+++ b/tests/test_token_counter.py@@ -1,4 +1,5 @@import unittest+import tests.contextfrom autogpt.token_counter import count_message_tokens, count_string_tokensdiff --git a/tests/unit/test_chat.py b/tests/unit/test_chat.pyindex 55a44492a0..774f410376 100644--- a/tests/unit/test_chat.py+++ b/tests/unit/test_chat.py@@ -1,6 +1,6 @@# Generated by CodiumAI-import unittestimport time+import unittestfrom unittest.mock import patchfrom autogpt.chat import create_chat_message, generate_contextdiff --git a/tests/unit/test_commands.py b/tests/unit/test_commands.pyindex e15709aa37..7e5426f0fc 100644--- a/tests/unit/test_commands.py+++ b/tests/unit/test_commands.py@@ -1,7 +1,8 @@-import autogpt.agent.agent_manager as agent_manager-from autogpt.app import start_agent, list_agents, execute_commandimport unittest-from unittest.mock import patch, MagicMock+from unittest.mock import MagicMock, patch++import autogpt.agent.agent_manager as agent_manager+from autogpt.app import execute_command, list_agents, start_agentclass TestCommands(unittest.TestCase):