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' of https://github.com/BillSchumacher/Auto-GPT into plugin-support
BillSchumacher03c137741ae2
diff --cc autogpt/__main__.pyindex cd597506eb,5f4622347d..c721088ace--- a/autogpt/__main__.py+++ b/autogpt/__main__.py@@@ -77,18 -35,13 +77,18 @@@ def main() -> Nonef"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()++ system_prompt = ai_config.construct_full_prompt()+ if cfg.debug_mode:- logger.typewriter_log("Prompt:", Fore.GREEN, prompt)++ logger.typewriter_log("Prompt:", Fore.GREEN, system_prompt)agent = Agent(ai_name=ai_name,memory=memory,full_message_history=full_message_history,next_action_count=next_action_count,+ command_registry=command_registry,+ config=ai_config,- prompt=prompt,- user_input=user_input,+ system_prompt=system_prompt,+ triggering_prompt=triggering_prompt,)agent.start_interaction_loop()diff --cc autogpt/agent/agent.pyindex 8117818ea4,dca614c7f2..b771b1de48--- a/autogpt/agent/agent.py+++ b/autogpt/agent/agent.py@@@ -1,11 -1,10 +1,10 @@@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 Config- from autogpt.json_fixes.bracket_termination import (- attempt_to_fix_json_by_finding_outermost_brackets,- )+ from autogpt.json_fixes.master_json_fix_method import fix_json_using_multiple_techniques+ from autogpt.json_validation.validate_json import validate_jsonfrom autogpt.logs import logger, print_assistant_thoughtsfrom autogpt.speech import say_textfrom autogpt.spinner import Spinner@@@ -31,19 -39,15 +39,19 @@@ class Agentmemory,full_message_history,next_action_count,+ command_registry,+ config,- prompt,- user_input,+ system_prompt,+ triggering_prompt,):self.ai_name = ai_nameself.memory = memoryself.full_message_history = full_message_historyself.next_action_count = next_action_count+ self.command_registry = command_registry+ self.config = config- self.prompt = prompt- self.user_input = user_input+ self.system_prompt = system_prompt+ self.triggering_prompt = triggering_promptdef start_interaction_loop(self):# Interaction Loop@@@ -67,29 -73,27 +77,31 @@@# Send message to AI, get responsewith Spinner("Thinking... "):assistant_reply = chat_with_ai(+ self,- self.prompt,- self.user_input,+ self.system_prompt,+ self.triggering_prompt,self.full_message_history,self.memory,cfg.fast_token_limit,) # TODO: This hardcodes the model to use GPT3.5. Make this an argument+ assistant_reply_json = fix_json_using_multiple_techniques(assistant_reply)+ for plugin in cfg.plugins:- assistant_reply = plugin.post_planning(self, assistant_reply)++ assistant_reply_json = plugin.post_planning(self, assistant_reply_json)+- # Print Assistant thoughts- print_assistant_thoughts(self.ai_name, assistant_reply)- # Get command name and arguments- try:- command_name, arguments = get_command(- attempt_to_fix_json_by_finding_outermost_brackets(assistant_reply)- )- if cfg.speak_mode:- say_text(f"I want to execute {command_name}")- except Exception as e:- logger.error("Error: \n", str(e))+ # Print Assistant thoughts+ if assistant_reply_json != {}:+ validate_json(assistant_reply_json, 'llm_response_format_1')+ # Get command name and arguments+ try:+ print_assistant_thoughts(self.ai_name, assistant_reply_json)+ command_name, arguments = get_command(assistant_reply_json)+ # command_name, arguments = assistant_reply_json_valid["command"]["name"], assistant_reply_json_valid["command"]["args"]+ if cfg.speak_mode:+ say_text(f"I want to execute {command_name}")+ except Exception as e:+ logger.error("Error: \n", str(e))if not cfg.continuous_mode and self.next_action_count == 0:### GET USER AUTHORIZATION TO EXECUTE COMMAND ###@@@ -112,9 -115,8 +123,9 @@@console_input = clean_input(Fore.MAGENTA + "Input:" + Style.RESET_ALL)+if console_input.lower().rstrip() == "y":- self.user_input = "GENERATE NEXT COMMAND JSON"+ user_input = "GENERATE NEXT COMMAND JSON"breakelif console_input.lower().startswith("y -"):try:@@@ -161,19 -163,12 +172,19 @@@f"Command {command_name} threw the following error: {arguments}")elif command_name == "human_feedback":- result = f"Human feedback: {self.user_input}"+ result = f"Human feedback: {user_input}"else:+ for plugin in cfg.plugins:+ command_name, arguments = plugin.pre_command(+ command_name, arguments+ )result = (f"Command {command_name} returned: "- f"{execute_command(command_name, arguments)}"+ f"{execute_command(self.command_registry, command_name, arguments, self.config.prompt_generator)}")++ for plugin in cfg.plugins:+ result = plugin.post_command(command_name, result)if self.next_action_count > 0:self.next_action_count -= 1diff --cc autogpt/app.pyindex 3a8bbc2a9a,19c075f0b0..97daaf05ba--- a/autogpt/app.py+++ b/autogpt/app.py@@@ -1,11 -1,15 +1,10 @@@""" Command and Control """import json- from typing import List, NoReturn, Union-+ from typing import List, NoReturn, Union, Dictfrom 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.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,@@@ -13,16 -17,8 +12,17 @@@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_text@@@ -139,9 -151,52 +137,14 @@@ def execute_commandreturn 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 == "download_file":+ if not CFG.allow_downloads:+ return "Error: You do not have user authorization to download files locally."+ return download_file(arguments["url"], arguments["file"])- 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 == "execute_shell":- if CFG.execute_local_commands:- return execute_shell(arguments["command_line"])- else:- return (- "You are not allowed to run local shell commands. To execute"- " shell commands, EXECUTE_LOCAL_COMMANDS must be set to 'True' "- "in your config. Do not attempt to bypass the restriction."- )- 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":diff --cc autogpt/commands/file_operations.pyindex 4d8d76b311,d273c1a34d..5faf6d40e4--- a/autogpt/commands/file_operations.py+++ b/autogpt/commands/file_operations.py@@@ -4,11 -4,16 +4,18 @@@ from __future__ import annotationimport osimport os.pathfrom pathlib import Path- from typing import Generator+ from typing import Generator, List+ import requests+ from requests.adapters import HTTPAdapter+ from requests.adapters import Retry+ from colorama import Fore, Back+ from autogpt.spinner import Spinner+ from autogpt.utils import readable_file_size-from autogpt.workspace import path_in_workspace, WORKSPACE_PATH++from autogpt.commands.command import command+from autogpt.workspace import WORKSPACE_PATH, path_in_workspace+LOG_FILE = "file_logger.txt"LOG_FILE_PATH = WORKSPACE_PATH / LOG_FILEdiff --cc autogpt/commands/git_operations.pyindex f5954032d4,675eb2283b..480d3a6ef2--- a/autogpt/commands/git_operations.py+++ b/autogpt/commands/git_operations.py@@@ -1,8 -1,7 +1,9 @@@"""Git operations for autogpt"""-import git+from git.repo import Repo++from autogpt.commands.command import commandfrom autogpt.config import Config+ from autogpt.workspace import path_in_workspaceCFG = Config()@@@ -25,8 -17,9 +26,9 @@@ def clone_repository(repo_url: str, clostr: The result of the clone operation"""split_url = repo_url.split("//")auth_repo_url = f"//{CFG.github_username}:{CFG.github_api_key}@".join(split_url)+ safe_clone_path = path_in_workspace(clone_path)try:- Repo.clone_from(auth_repo_url, clone_path)- return f"""Cloned {repo_url} to {clone_path}"""- git.Repo.clone_from(auth_repo_url, safe_clone_path)++ Repo.clone_from(auth_repo_url, safe_clone_path)+ return f"""Cloned {repo_url} to {safe_clone_path}"""except Exception as e:return f"Error: {str(e)}"diff --cc autogpt/prompts/generator.pyindex 24768203d5,0ad7046a0c..b422b6d6ce--- a/autogpt/prompts/generator.py+++ b/autogpt/prompts/generator.py@@@ -120,14 -109,10 +120,14 @@@ class PromptGeneratorstr: 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()++ str(item) for item in self.command_registry.commands.values() if item.enabled+ ]+ # 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))