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.
isort implemented
Merwane Hamadicf9a94a8b673
diff --git a/autogpt/__main__.py b/autogpt/__main__.pyindex 5f4622347d..64ed398e03 100644--- a/autogpt/__main__.py+++ b/autogpt/__main__.py@@ -1,12 +1,15 @@"""Main script for the autogpt package."""import logging+from colorama import Fore+from autogpt.agent.agent import Agentfrom autogpt.args import parse_argumentsfrom autogpt.config import Config, check_openai_api_keyfrom autogpt.logs import loggerfrom autogpt.memory import get_memoryfrom autogpt.prompt import construct_prompt+# Load environment variables from .env filediff --git a/autogpt/agent/agent.py b/autogpt/agent/agent.pyindex dca614c7f2..50e497f1f5 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.master_json_fix_method import fix_json_using_multiple_techniques@@ -84,7 +84,7 @@ class Agent:# Print Assistant thoughtsif assistant_reply_json != {}:- validate_json(assistant_reply_json, 'llm_response_format_1')+ validate_json(assistant_reply_json, "llm_response_format_1")# Get command name and argumentstry:print_assistant_thoughts(self.ai_name, assistant_reply_json)diff --git a/autogpt/agent/agent_manager.py b/autogpt/agent/agent_manager.pyindex 79375ea8d4..898767a485 100644--- a/autogpt/agent/agent_manager.py+++ b/autogpt/agent/agent_manager.py@@ -1,8 +1,10 @@"""Agent manager for managing GPT agents"""from __future__ import annotations+from typing import Union-from autogpt.llm_utils import create_chat_completion+from autogpt.config.config import Singleton+from autogpt.llm_utils import create_chat_completionclass AgentManager(metaclass=Singleton):diff --git a/autogpt/app.py b/autogpt/app.pyindex 0927eccca1..381f5a2aa0 100644--- a/autogpt/app.py+++ b/autogpt/app.py@@ -1,15 +1,10 @@""" Command and Control """import json-from typing import List, NoReturn, Union, Dict+from typing import Dict, List, NoReturn, Union+from autogpt.agent.agent_manager import AgentManager-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.evaluate_code import evaluate_codefrom autogpt.commands.execute_code import (execute_python_file,execute_shell,@@ -18,19 +13,24 @@ from autogpt.commands.execute_code import (from autogpt.commands.file_operations import (append_to_file,delete_file,+ download_file,read_file,search_files,write_to_file,- download_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.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()@@ -133,11 +133,14 @@ def execute_command(command_name: str, arguments):# google_result can be a list or a string depending on the search resultsif isinstance(google_result, list):- safe_message = [google_result_single.encode('utf-8', 'ignore') for google_result_single in google_result]+ 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')+ safe_message = google_result.encode("utf-8", "ignore")- return safe_message.decode('utf-8')+ return safe_message.decode("utf-8")elif command_name == "memory_add":memory = get_memory(CFG)return memory.add(arguments["string"])diff --git a/autogpt/args.py b/autogpt/args.pyindex f0e9c07a36..5ca4221ccd 100644--- a/autogpt/args.py+++ b/autogpt/args.py@@ -1,7 +1,8 @@"""This module contains the argument parsing logic for the script."""import argparse-from colorama import Fore, Back, Style+from colorama import Back, Fore, Style+from autogpt import utilsfrom autogpt.config import Configfrom autogpt.logs import logger@@ -64,10 +65,10 @@ def parse_arguments() -> None:" skip the re-prompt.",)parser.add_argument(- '--allow-downloads',- action='store_true',- dest='allow_downloads',- help='Dangerous: Allows Auto-GPT to download files natively.'+ "--allow-downloads",+ action="store_true",+ dest="allow_downloads",+ help="Dangerous: Allows Auto-GPT to download files natively.",)args = parser.parse_args()@@ -141,10 +142,17 @@ def parse_arguments() -> None:if args.allow_downloads:logger.typewriter_log("Native Downloading:", Fore.GREEN, "ENABLED")- logger.typewriter_log("WARNING: ", Fore.YELLOW,- f"{Back.LIGHTYELLOW_EX}Auto-GPT will now be able to download and save files to your machine.{Back.RESET} " +- "It is recommended that you monitor any files it downloads carefully.")- logger.typewriter_log("WARNING: ", Fore.YELLOW, f"{Back.RED + Style.BRIGHT}ALWAYS REMEMBER TO NEVER OPEN FILES YOU AREN'T SURE OF!{Style.RESET_ALL}")+ logger.typewriter_log(+ "WARNING: ",+ Fore.YELLOW,+ f"{Back.LIGHTYELLOW_EX}Auto-GPT will now be able to download and save files to your machine.{Back.RESET} "+ + "It is recommended that you monitor any files it downloads carefully.",+ )+ logger.typewriter_log(+ "WARNING: ",+ Fore.YELLOW,+ f"{Back.RED + Style.BRIGHT}ALWAYS REMEMBER TO NEVER OPEN FILES YOU AREN'T SURE OF!{Style.RESET_ALL}",+ )CFG.allow_downloads = Trueif args.browser_name:diff --git a/autogpt/commands/audio_text.py b/autogpt/commands/audio_text.pyindex 84819d5ed7..cae32d4eb7 100644--- a/autogpt/commands/audio_text.py+++ b/autogpt/commands/audio_text.py@@ -1,6 +1,7 @@-import requestsimport json+import requests+from autogpt.config import Configfrom autogpt.workspace import path_in_workspacediff --git a/autogpt/commands/execute_code.py b/autogpt/commands/execute_code.pyindex 705223748e..a524081e0f 100644--- a/autogpt/commands/execute_code.py+++ b/autogpt/commands/execute_code.py@@ -5,7 +5,7 @@ import subprocessimport dockerfrom docker.errors import ImageNotFound-from autogpt.workspace import path_in_workspace, WORKSPACE_PATH+from autogpt.workspace import WORKSPACE_PATH, path_in_workspacedef execute_python_file(file: str) -> str:diff --git a/autogpt/commands/file_operations.py b/autogpt/commands/file_operations.pyindex 9dcf819480..72b02b5d31 100644--- a/autogpt/commands/file_operations.py+++ b/autogpt/commands/file_operations.py@@ -5,14 +5,14 @@ import osimport os.pathfrom pathlib import Pathfrom typing import Generator, List+import requests-from requests.adapters import HTTPAdapter-from requests.adapters import Retry-from colorama import Fore, Back+from colorama import Back, Fore+from requests.adapters import HTTPAdapter, Retry+from autogpt.spinner import Spinnerfrom autogpt.utils import readable_file_size-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_FILE@@ -47,7 +47,7 @@ def log_operation(operation: str, filename: str) -> None:with open(LOG_FILE_PATH, "w", encoding="utf-8") as f:f.write("File Operation Logger ")- append_to_file(LOG_FILE, log_entry, shouldLog = False)+ append_to_file(LOG_FILE, log_entry, shouldLog=False)def split_file(@@ -241,23 +241,23 @@ def download_file(url, filename):session = requests.Session()retry = Retry(total=3, backoff_factor=1, status_forcelist=[502, 503, 504])adapter = HTTPAdapter(max_retries=retry)- session.mount('http://', adapter)- session.mount('https://', adapter)+ session.mount("http://", adapter)+ session.mount("https://", adapter)total_size = 0downloaded_size = 0with session.get(url, allow_redirects=True, stream=True) as r:r.raise_for_status()- total_size = int(r.headers.get('Content-Length', 0))+ total_size = int(r.headers.get("Content-Length", 0))downloaded_size = 0- with open(safe_filename, 'wb') as f:+ with open(safe_filename, "wb") as f:for chunk in r.iter_content(chunk_size=8192):f.write(chunk)downloaded_size += len(chunk)- # Update the progress message+ # Update the progress messageprogress = f"{readable_file_size(downloaded_size)} / {readable_file_size(total_size)}"spinner.update_message(f"{message} {progress}")diff --git a/autogpt/commands/git_operations.py b/autogpt/commands/git_operations.pyindex 05ce2a2129..028f3b8da4 100644--- a/autogpt/commands/git_operations.py+++ b/autogpt/commands/git_operations.py@@ -1,5 +1,6 @@"""Git operations for autogpt"""import git+from autogpt.config import Configfrom autogpt.workspace import path_in_workspacediff --git a/autogpt/commands/image_gen.py b/autogpt/commands/image_gen.pyindex 6243616ea8..4e8b47d687 100644--- a/autogpt/commands/image_gen.py+++ b/autogpt/commands/image_gen.py@@ -7,6 +7,7 @@ from base64 import b64decodeimport openaiimport requestsfrom PIL import Image+from autogpt.config import Configfrom autogpt.workspace import path_in_workspacediff --git a/autogpt/commands/twitter.py b/autogpt/commands/twitter.pyindex dc4d450c1f..3eaed36e20 100644--- a/autogpt/commands/twitter.py+++ b/autogpt/commands/twitter.py@@ -1,5 +1,6 @@-import tweepyimport os++import tweepyfrom dotenv import load_dotenvload_dotenv()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 70ada90741..406338f46f 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_memory@@ -79,7 +79,7 @@ def check_local_file_access(url: str) -> bool:"http://0000","http://0000/","https://0000",- "https://0000/"+ "https://0000/",]return any(url.startswith(prefix) for prefix in local_prefixes)diff --git a/autogpt/commands/web_selenium.py b/autogpt/commands/web_selenium.pyindex c0b1b2492f..9db5d03502 100644--- a/autogpt/commands/web_selenium.py+++ b/autogpt/commands/web_selenium.py@@ -1,23 +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 sys import platform+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++import autogpt.processing.text as summaryfrom autogpt.config import Config-from sys import platform+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 138a1adb6f..35a086536c 100644--- a/autogpt/commands/write_tests.py+++ b/autogpt/commands/write_tests.py@@ -2,6 +2,7 @@from __future__ import annotationsimport json+from 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 86171357ba..d50c30beee 100644--- a/autogpt/config/ai_config.py+++ b/autogpt/config/ai_config.py@@ -6,6 +6,7 @@ from __future__ import annotationsimport osfrom typing import Type+import yamldiff --git a/autogpt/config/config.py b/autogpt/config/config.pyindex 7d470cba9f..bc75b03192 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)@@ -74,7 +73,9 @@ class Config(metaclass=Singleton):self.weaviate_scopes = os.getenv("WEAVIATE_SCOPES", None)self.weaviate_embedded_path = os.getenv("WEAVIATE_EMBEDDED_PATH")self.weaviate_api_key = os.getenv("WEAVIATE_API_KEY", None)- self.use_weaviate_embedded = os.getenv("USE_WEAVIATE_EMBEDDED", "False") == "True"+ self.use_weaviate_embedded = (+ os.getenv("USE_WEAVIATE_EMBEDDED", "False") == "True"+ )# milvus configuration, e.g., localhost:19530.self.milvus_addr = os.getenv("MILVUS_ADDR", "localhost:19530")diff --git a/autogpt/json_fixes/auto_fix.py b/autogpt/json_fixes/auto_fix.pyindex 0d3bd73ce1..7eb1e4bdb4 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 dd9a83764e..6c6c58eea6 100644--- a/autogpt/json_fixes/bracket_termination.py+++ b/autogpt/json_fixes/bracket_termination.py@@ -4,6 +4,7 @@ from __future__ import annotationsimport contextlibimport jsonfrom typing import Optional+from autogpt.config import ConfigCFG = Config()diff --git a/autogpt/json_fixes/master_json_fix_method.py b/autogpt/json_fixes/master_json_fix_method.pyindex 7a2cf3cc81..a77bf670b8 100644--- a/autogpt/json_fixes/master_json_fix_method.py+++ b/autogpt/json_fixes/master_json_fix_method.py@@ -3,13 +3,15 @@ from typing import Any, Dictfrom autogpt.config import Configfrom autogpt.logs import loggerfrom autogpt.speech import say_text+CFG = Config()def fix_json_using_multiple_techniques(assistant_reply: str) -> Dict[Any, Any]:- from autogpt.json_fixes.parsing import attempt_to_fix_json_by_finding_outermost_brackets-- from autogpt.json_fixes.parsing import fix_and_parse_json+ from autogpt.json_fixes.parsing import (+ attempt_to_fix_json_by_finding_outermost_brackets,+ fix_and_parse_json,+ )# Parse and print Assistant responseassistant_reply_json = fix_and_parse_json(assistant_reply)@@ -21,7 +23,10 @@ def fix_json_using_multiple_techniques(assistant_reply: str) -> Dict[Any, Any]:if assistant_reply_json != {}:return assistant_reply_json- logger.error("Error: The following AI output couldn't be converted to a JSON:\n", assistant_reply)+ logger.error(+ "Error: The following AI output couldn't be converted to a JSON:\n",+ assistant_reply,+ )if CFG.speak_mode:say_text("I have received an invalid JSON response from the OpenAI API.")diff --git a/autogpt/json_fixes/parsing.py b/autogpt/json_fixes/parsing.pyindex 1e391eed7c..e02f78cd2a 100644--- a/autogpt/json_fixes/parsing.py+++ b/autogpt/json_fixes/parsing.py@@ -4,8 +4,10 @@ from __future__ import annotationsimport contextlibimport jsonfrom typing import Any, Dict, Union+from colorama import Forefrom regex import regex+from autogpt.config import Configfrom autogpt.json_fixes.auto_fix import fix_jsonfrom autogpt.json_fixes.bracket_termination import balance_bracesdiff --git a/autogpt/json_validation/validate_json.py b/autogpt/json_validation/validate_json.pyindex 440c3b0b91..ea74ec95d8 100644--- a/autogpt/json_validation/validate_json.py+++ b/autogpt/json_validation/validate_json.py@@ -1,5 +1,7 @@import json+from jsonschema import Draft7Validator+from autogpt.config import Configfrom autogpt.logs import logger@@ -19,7 +21,9 @@ def validate_json(json_object: object, schema_name: object) -> object:if errors := sorted(validator.iter_errors(json_object), key=lambda e: e.path):logger.error("The JSON object is invalid.")if CFG.debug_mode:- logger.error(json.dumps(json_object, indent=4)) # Replace 'json_object' with the variable containing the JSON data+ logger.error(+ json.dumps(json_object, indent=4)+ ) # Replace 'json_object' with the variable containing the JSON datalogger.error("The following issues were found:")for error in errors:diff --git a/autogpt/llm_utils.py b/autogpt/llm_utils.pyindex 791fd31a81..821820ffab 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, Style+from openai.error import APIError, RateLimitErrorfrom autogpt.config import Configfrom autogpt.logs import logger@@ -105,8 +105,9 @@ def create_chat_completion()if not warned_user:logger.double_check(- f"Please double check that you have setup a {Fore.CYAN + Style.BRIGHT}PAID{Style.RESET_ALL} OpenAI API Account. " +- f"You can read more here: {Fore.CYAN}https://github.com/Significant-Gravitas/Auto-GPT#openai-api-keys-configuration{Fore.RESET}")+ f"Please double check that you have setup a {Fore.CYAN + Style.BRIGHT}PAID{Style.RESET_ALL} OpenAI API Account. "+ + f"You can read more here: {Fore.CYAN}https://github.com/Significant-Gravitas/Auto-GPT#openai-api-keys-configuration{Fore.RESET}"+ )warned_user = Trueexcept APIError as e:if e.http_status == 502:@@ -125,8 +126,8 @@ def create_chat_completion(logger.typewriter_log("FAILED TO GET RESPONSE FROM OPENAI",Fore.RED,- "Auto-GPT has failed to get a response from OpenAI's services. " +- f"Try running Auto-GPT again, and if the problem the persists try running it with `{Fore.CYAN}--debug{Fore.RESET}`."+ "Auto-GPT has failed to get a response from OpenAI's services. "+ + f"Try running Auto-GPT again, and if the problem the persists try running it with `{Fore.CYAN}--debug{Fore.RESET}`.",)logger.double_check()if CFG.debug_mode:diff --git a/autogpt/logs.py b/autogpt/logs.pyindex c1e436db97..df3487f2c1 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()@@ -47,7 +47,7 @@ class Logger(metaclass=Singleton):# Info handler in activity.logself.file_handler = logging.FileHandler(- os.path.join(log_dir, log_file), 'a', 'utf-8'+ os.path.join(log_dir, log_file), "a", "utf-8")self.file_handler.setLevel(logging.DEBUG)info_formatter = AutoGptFormatter(@@ -57,7 +57,7 @@ class Logger(metaclass=Singleton):# Error handler error.logerror_handler = logging.FileHandler(- os.path.join(log_dir, error_file), 'a', 'utf-8'+ os.path.join(log_dir, error_file), "a", "utf-8")error_handler.setLevel(logging.ERROR)error_formatter = AutoGptFormatter(@@ -79,7 +79,7 @@ class Logger(metaclass=Singleton):self.logger.setLevel(logging.DEBUG)def typewriter_log(- self, title="", title_color="", content="", speak_text=False, level=logging.INFO+ self, title="", title_color="", content="", speak_text=False, level=logging.INFO):if speak_text and CFG.speak_mode:say_text(f"{title}. {content}")@@ -95,18 +95,18 @@ class Logger(metaclass=Singleton):)def debug(- self,- message,- title="",- title_color="",+ self,+ message,+ title="",+ title_color="",):self._log(title, title_color, message, logging.DEBUG)def warn(- self,- message,- title="",- title_color="",+ self,+ message,+ title="",+ title_color="",):self._log(title, title_color, message, logging.WARN)@@ -180,10 +180,10 @@ class AutoGptFormatter(logging.Formatter):def format(self, record: LogRecord) -> str:if hasattr(record, "color"):record.title_color = (- getattr(record, "color")- + getattr(record, "title")- + " "- + Style.RESET_ALL+ getattr(record, "color")+ + getattr(record, "title")+ + " "+ + Style.RESET_ALL)else:record.title_color = getattr(record, "title")@@ -294,7 +294,9 @@ def print_assistant_thoughts(ai_name, assistant_reply):logger.error("Error: \n", call_stack)-def print_assistant_thoughts(ai_name: object, assistant_reply_json_valid: object) -> None:+def print_assistant_thoughts(+ ai_name: object, assistant_reply_json_valid: object+) -> None:assistant_thoughts_reasoning = Noneassistant_thoughts_plan = Noneassistant_thoughts_speak = None@@ -310,9 +312,7 @@ def print_assistant_thoughts(ai_name: object, assistant_reply_json_valid: objectlogger.typewriter_log(f"{ai_name.upper()} THOUGHTS:", Fore.YELLOW, f"{assistant_thoughts_text}")- logger.typewriter_log(- "REASONING:", Fore.YELLOW, f"{assistant_thoughts_reasoning}"- )+ logger.typewriter_log("REASONING:", Fore.YELLOW, f"{assistant_thoughts_reasoning}")if assistant_thoughts_plan:logger.typewriter_log("PLAN:", Fore.YELLOW, "")# If it's a list, join it into a string@@ -326,9 +326,7 @@ def print_assistant_thoughts(ai_name: object, assistant_reply_json_valid: objectfor line in lines:line = line.lstrip("- ")logger.typewriter_log("- ", Fore.GREEN, line.strip())- logger.typewriter_log(- "CRITICISM:", Fore.YELLOW, f"{assistant_thoughts_criticism}"- )+ logger.typewriter_log("CRITICISM:", Fore.YELLOW, f"{assistant_thoughts_criticism}")# Speak the assistant's thoughtsif CFG.speak_mode and assistant_thoughts_speak:say_text(assistant_thoughts_speak)diff --git a/autogpt/memory/milvus.py b/autogpt/memory/milvus.pyindex 7a2571d0a3..44aa72b956 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 35e7844a2a..5408e9a97a 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 {@@ -14,7 +16,7 @@ def default_schema(weaviate_index):{"name": "raw_text","dataType": ["text"],- "description": "original text for the embedding"+ "description": "original text for the embedding",}],}@@ -24,16 +26,20 @@ class WeaviateMemory(MemoryProviderSingleton):def __init__(self, cfg):auth_credentials = self._build_auth_credentials(cfg)- url = f'{cfg.weaviate_protocol}://{cfg.weaviate_host}:{cfg.weaviate_port}'+ url = f"{cfg.weaviate_protocol}://{cfg.weaviate_host}:{cfg.weaviate_port}"if cfg.use_weaviate_embedded:- self.client = Client(embedded_options=EmbeddedOptions(- hostname=cfg.weaviate_host,- port=int(cfg.weaviate_port),- persistence_data_path=cfg.weaviate_embedded_path- ))+ self.client = Client(+ embedded_options=EmbeddedOptions(+ hostname=cfg.weaviate_host,+ port=int(cfg.weaviate_port),+ persistence_data_path=cfg.weaviate_embedded_path,+ )+ )- print(f"Weaviate Embedded running on: {url} with persistence path: {cfg.weaviate_embedded_path}")+ print(+ f"Weaviate Embedded running on: {url} with persistence path: {cfg.weaviate_embedded_path}"+ )else:self.client = Client(url, auth_client_secret=auth_credentials)@@ -56,7 +62,9 @@ class WeaviateMemory(MemoryProviderSingleton):def _build_auth_credentials(self, cfg):if cfg.weaviate_username and cfg.weaviate_password:- return weaviate.AuthClientPassword(cfg.weaviate_username, cfg.weaviate_password)+ return weaviate.AuthClientPassword(+ cfg.weaviate_username, cfg.weaviate_password+ )if cfg.weaviate_api_key:return weaviate.AuthApiKey(api_key=cfg.weaviate_api_key)else:@@ -66,16 +74,14 @@ class WeaviateMemory(MemoryProviderSingleton):vector = get_ada_embedding(data)doc_uuid = generate_uuid5(data, self.index)- data_object = {- 'raw_text': data- }+ data_object = {"raw_text": data}with self.client.batch as batch:batch.add_data_object(uuid=doc_uuid,data_object=data_object,class_name=self.index,- vector=vector+ vector=vector,)return f"Inserting data into memory at uuid: {doc_uuid}:\n data: {data}"@@ -91,29 +97,31 @@ class WeaviateMemory(MemoryProviderSingleton):# after a call to delete_allself._create_schema()- return 'Obliterated'+ return "Obliterated"def get_relevant(self, data, num_relevant=5):query_embedding = get_ada_embedding(data)try:- results = self.client.query.get(self.index, ['raw_text']) \- .with_near_vector({'vector': query_embedding, 'certainty': 0.7}) \- .with_limit(num_relevant) \- .do()+ results = (+ self.client.query.get(self.index, ["raw_text"])+ .with_near_vector({"vector": query_embedding, "certainty": 0.7})+ .with_limit(num_relevant)+ .do()+ )- if len(results['data']['Get'][self.index]) > 0:- return [str(item['raw_text']) for item in results['data']['Get'][self.index]]+ if len(results["data"]["Get"][self.index]) > 0:+ return [+ str(item["raw_text"]) for item in results["data"]["Get"][self.index]+ ]else:return []except Exception as err:- print(f'Unexpected error {err=}, {type(err)=}')+ print(f"Unexpected error {err=}, {type(err)=}")return []def get_stats(self):- result = self.client.query.aggregate(self.index) \- .with_meta_count() \- .do()- class_data = result['data']['Aggregate'][self.index]+ result = self.client.query.aggregate(self.index).with_meta_count().do()+ class_data = result["data"]["Aggregate"][self.index]- return class_data[0]['meta'] if class_data else {}+ return class_data[0]["meta"] if class_data else {}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 657b0b0eb4..52add81401 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/prompt.py b/autogpt/prompt.pyindex 33098af035..a0456305a5 100644--- a/autogpt/prompt.py+++ b/autogpt/prompt.py@@ -1,9 +1,10 @@from colorama import Fore++from autogpt.config import Configfrom autogpt.config.ai_config import AIConfigfrom autogpt.config.config import Configfrom autogpt.logs import loggerfrom autogpt.promptgenerator import PromptGenerator-from autogpt.config import Configfrom autogpt.setup import prompt_userfrom autogpt.utils import clean_input@@ -92,11 +93,7 @@ def get_prompt() -> str:# Only add the audio to text command if the model is specifiedif cfg.huggingface_audio_to_text_model:commands.append(- (- "Convert Audio to text",- "read_audio_from_file",- {"file": "<file>"}- ),+ ("Convert Audio to text", "read_audio_from_file", {"file": "<file>"}),)# Only add shell command to the prompt if the AI is allowed to execute it@@ -112,7 +109,7 @@ def get_prompt() -> str:("Execute Shell Command Popen, non-interactive commands only","execute_shell_popen",- {"command_line": "<command_line>"}+ {"command_line": "<command_line>"},),)@@ -122,7 +119,7 @@ def get_prompt() -> str:("Downloads a file from the internet, and stores it locally","download_file",- {"url": "<file_url>", "file": "<saved_filename>"}+ {"url": "<file_url>", "file": "<saved_filename>"},),)diff --git a/autogpt/setup.py b/autogpt/setup.pyindex 79661905f4..1c46771759 100644--- a/autogpt/setup.py+++ b/autogpt/setup.py@@ -1,5 +1,6 @@"""Set up 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 b9298f55aa..821fdf2f48 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 186ec6fc02..ea84efd8ca 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/data_ingestion.py b/data_ingestion.pyindex 01bafc2ad0..b89a33dafd 100644--- a/data_ingestion.py+++ b/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/pyproject.toml b/pyproject.tomlindex 91f6df38d8..fdb43d66e4 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -36,4 +36,5 @@ skip = '''.venv/*reports/*dist/*+'''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 4acea0ffda..015eab0548 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 WeaviateMemoryclass TestWeaviateMemory(unittest.TestCase):@@ -25,13 +25,17 @@ class TestWeaviateMemory(unittest.TestCase):if cls.cfg.use_weaviate_embedded:from weaviate.embedded import EmbeddedOptions- cls.client = Client(embedded_options=EmbeddedOptions(- hostname=cls.cfg.weaviate_host,- port=int(cls.cfg.weaviate_port),- persistence_data_path=cls.cfg.weaviate_embedded_path- ))+ cls.client = Client(+ embedded_options=EmbeddedOptions(+ hostname=cls.cfg.weaviate_host,+ port=int(cls.cfg.weaviate_port),+ persistence_data_path=cls.cfg.weaviate_embedded_path,+ )+ )else:- cls.client = Client(f"{cls.cfg.weaviate_protocol}://{cls.cfg.weaviate_host}:{self.cfg.weaviate_port}")+ cls.client = Client(+ f"{cls.cfg.weaviate_protocol}://{cls.cfg.weaviate_host}:{self.cfg.weaviate_port}"+ )cls.index = WeaviateMemory.format_classname(cls.cfg.memory_index)@@ -44,6 +48,7 @@ class TestWeaviateMemory(unittest.TestCase):USE_WEAVIATE_EMBEDDED=TrueWEAVIATE_EMBEDDED_PATH="/home/me/.local/share/weaviate""""+def setUp(self):try:self.client.schema.delete_class(self.index)@@ -53,23 +58,23 @@ class TestWeaviateMemory(unittest.TestCase):self.memory = WeaviateMemory(self.cfg)def test_add(self):- doc = 'You are a Titan name Thanos and you are looking for the Infinity Stones'+ doc = "You are a Titan name Thanos and you are looking for the Infinity Stones"self.memory.add(doc)- result = self.client.query.get(self.index, ['raw_text']).do()- actual = result['data']['Get'][self.index]+ result = self.client.query.get(self.index, ["raw_text"]).do()+ actual = result["data"]["Get"][self.index]self.assertEqual(len(actual), 1)- self.assertEqual(actual[0]['raw_text'], doc)+ self.assertEqual(actual[0]["raw_text"], doc)def test_get(self):- doc = 'You are an Avenger and swore to defend the Galaxy from a menace called Thanos'+ doc = "You are an Avenger and swore to defend the Galaxy from a menace called Thanos"with self.client.batch as batch:batch.add_data_object(uuid=get_valid_uuid(uuid4()),- data_object={'raw_text': doc},+ data_object={"raw_text": doc},class_name=self.index,- vector=get_ada_embedding(doc)+ vector=get_ada_embedding(doc),)batch.flush()@@ -81,8 +86,8 @@ class TestWeaviateMemory(unittest.TestCase):def test_get_stats(self):docs = [- 'You are now about to count the number of docs in this index',- 'And then you about to find out if you can count correctly'+ "You are now about to count the number of docs in this index",+ "And then you about to find out if you can count correctly",][self.memory.add(doc) for doc in docs]@@ -90,23 +95,23 @@ class TestWeaviateMemory(unittest.TestCase):stats = self.memory.get_stats()self.assertTrue(stats)- self.assertTrue('count' in stats)- self.assertEqual(stats['count'], 2)+ self.assertTrue("count" in stats)+ self.assertEqual(stats["count"], 2)def test_clear(self):docs = [- 'Shame this is the last test for this class',- 'Testing is fun when someone else is doing it'+ "Shame this is the last test for this class",+ "Testing is fun when someone else is doing it",][self.memory.add(doc) for doc in docs]- self.assertEqual(self.memory.get_stats()['count'], 2)+ self.assertEqual(self.memory.get_stats()["count"], 2)self.memory.clear()- self.assertEqual(self.memory.get_stats()['count'], 0)+ self.assertEqual(self.memory.get_stats()["count"], 0)-if __name__ == '__main__':+if __name__ == "__main__":unittest.main()diff --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_context