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.

Fix all commands and cleanup

BillSchumacherd7679d755f18
diff --git a/autogpt/app.py b/autogpt/app.py
index cf1ec5f9b2..7c24f70162 100644
--- a/autogpt/app.py
+++ b/autogpt/app.py
@@ -3,33 +3,9 @@ import json
from typing import Dict, List, NoReturn, Union
from autogpt.agent.agent_manager import AgentManager
-from autogpt.commands.analyze_code import analyze_code
-from autogpt.commands.audio_text import read_audio_from_file
from autogpt.commands.command import CommandRegistry, command
-from autogpt.commands.evaluate_code import evaluate_code
-from autogpt.commands.execute_code import (
- execute_python_file,
- execute_shell,
- execute_shell_popen,
-)
-from autogpt.commands.file_operations import (
- append_to_file,
- delete_file,
- download_file,
- read_file,
- 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 Config
-from autogpt.json_utils.json_fix_llm import fix_and_parse_json
from autogpt.memory import get_memory
from autogpt.processing.text import summarize_text
from autogpt.prompts.generator import PromptGenerator
@@ -137,26 +113,8 @@ def execute_command(
command_name = map_command_synonyms(command_name.lower())
if command_name == "memory_add":
- return memory.add(arguments["string"])
- 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 == "analyze_code":
- return analyze_code(arguments["code"])
- 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 == "execute_shell_popen":
- if CFG.execute_local_commands:
- return execute_shell_popen(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."
- )
+ return get_memory(CFG).add(arguments["string"])
+
# 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
@@ -177,6 +135,7 @@ def execute_command(
return f"Error: {str(e)}"
+@command("get_text_summary", "Get text summary", '"url": "<url>", "question": "<question>"')
def get_text_summary(url: str, question: str) -> str:
"""Return the results of a Google search
@@ -192,6 +151,7 @@ def get_text_summary(url: str, question: str) -> str:
return f""" "Result" : {summary}"""
+@command("get_hyperlinks", "Get text summary", '"url": "<url>"')
def get_hyperlinks(url: str) -> Union[str, List[str]]:
"""Return the results of a Google search
diff --git a/autogpt/cli.py b/autogpt/cli.py
index 30eb9c2385..51a946a73e 100644
--- a/autogpt/cli.py
+++ b/autogpt/cli.py
@@ -130,13 +130,14 @@ def main(
cfg.set_plugins(scan_plugins(cfg, cfg.debug_mode))
# Create a CommandRegistry instance and scan default folder
command_registry = CommandRegistry()
+ command_registry.import_commands("autogpt.commands.analyze_code")
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.improve_code")
command_registry.import_commands("autogpt.commands.twitter")
command_registry.import_commands("autogpt.commands.web_selenium")
command_registry.import_commands("autogpt.commands.write_tests")
diff --git a/autogpt/commands/analyze_code.py b/autogpt/commands/analyze_code.py
index e02ea4c5b4..b87d73e1b7 100644
--- a/autogpt/commands/analyze_code.py
+++ b/autogpt/commands/analyze_code.py
@@ -1,9 +1,15 @@
"""Code evaluation module."""
from __future__ import annotations
+from autogpt.commands.command import command
from autogpt.llm_utils import call_ai_function
+@command(
+ "analyze_code",
+ "Analyze Code",
+ '"code": "<full_code_string>"',
+)
def analyze_code(code: str) -> list[str]:
"""
A function that takes in a string and returns a response from create chat
diff --git a/autogpt/commands/audio_text.py b/autogpt/commands/audio_text.py
index 421a1f18ee..b409fefdce 100644
--- a/autogpt/commands/audio_text.py
+++ b/autogpt/commands/audio_text.py
@@ -13,11 +13,11 @@ CFG = Config()
@command(
"read_audio_from_file",
"Convert Audio to text",
- '"file": "<file>"',
+ '"filename": "<filename>"',
CFG.huggingface_audio_to_text_model,
"Configure huggingface_audio_to_text_model.",
)
-def read_audio_from_file(audio_path: str) -> str:
+def read_audio_from_file(filename: str) -> str:
"""
Convert audio to text.
@@ -27,7 +27,7 @@ def read_audio_from_file(audio_path: str) -> str:
Returns:
str: The text from the audio
"""
- audio_path = path_in_workspace(audio_path)
+ audio_path = path_in_workspace(filename)
with open(audio_path, "rb") as audio_file:
audio = audio_file.read()
return read_audio(audio)
diff --git a/autogpt/commands/command.py b/autogpt/commands/command.py
index f21b1b526c..26fa445bb9 100644
--- a/autogpt/commands/command.py
+++ b/autogpt/commands/command.py
@@ -20,7 +20,7 @@ class Command:
name: str,
description: str,
method: Callable[..., Any],
- signature: str = None,
+ signature: str = '',
enabled: bool = True,
disabled_reason: Optional[str] = None,
):
@@ -126,7 +126,7 @@ class CommandRegistry:
def command(
name: str,
description: str,
- signature: str = None,
+ signature: str = '',
enabled: bool = True,
disabled_reason: Optional[str] = None,
) -> Callable[..., Any]:
diff --git a/autogpt/commands/execute_code.py b/autogpt/commands/execute_code.py
index 5dd56605d0..ff35d4286f 100644
--- a/autogpt/commands/execute_code.py
+++ b/autogpt/commands/execute_code.py
@@ -12,17 +12,17 @@ from autogpt.workspace import WORKSPACE_PATH, path_in_workspace
CFG = Config()
-@command("execute_python_file", "Execute Python File", '"file": "<file>"')
-def execute_python_file(file: str) -> str:
+@command("execute_python_file", "Execute Python File", '"filename": "<filename>"')
+def execute_python_file(filename: str) -> str:
"""Execute a Python file in a Docker container and return the output
Args:
- file (str): The name of the file to execute
+ filename (str): The name of the file to execute
Returns:
str: The output of the file
"""
-
+ file = filename
print(f"Executing file '{file}' in workspace '{WORKSPACE_PATH}'")
if not file.endswith(".py"):
@@ -138,9 +138,16 @@ def execute_shell(command_line: str) -> str:
os.chdir(current_dir)
- return output
-
+@command(
+ "execute_shell_popen",
+ "Execute Shell Command, non-interactive commands only",
+ '"command_line": "<command_line>"',
+ CFG.execute_local_commands,
+ "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.",
+)
def execute_shell_popen(command_line) -> str:
"""Execute a shell command with Popen and returns an english description
of the event and the process id
diff --git a/autogpt/commands/file_operations.py b/autogpt/commands/file_operations.py
index 28ff0e5292..d8f8e66402 100644
--- a/autogpt/commands/file_operations.py
+++ b/autogpt/commands/file_operations.py
@@ -9,11 +9,13 @@ import requests
from colorama import Back, Fore
from requests.adapters import HTTPAdapter, Retry
+from autogpt.config import Config
from autogpt.commands.command import command
from autogpt.spinner import Spinner
from autogpt.utils import readable_file_size
from autogpt.workspace import WORKSPACE_PATH, path_in_workspace
+CFG = Config()
LOG_FILE = "file_logger.txt"
LOG_FILE_PATH = WORKSPACE_PATH / LOG_FILE
@@ -82,7 +84,7 @@ def split_file(
start += max_length - overlap
-@command("read_file", "Read file", '"file": "<file>"')
+@command("read_file", "Read file", '"filename": "<filename>"')
def read_file(filename: str) -> str:
"""Read a file and return the contents
@@ -135,7 +137,7 @@ def ingest_file(
print(f"Error while ingesting file '{filename}': {str(e)}")
-@command("write_to_file", "Write to file", '"file": "<file>", "text": "<text>"')
+@command("write_to_file", "Write to file", '"filename": "<filename>", "text": "<text>"')
def write_to_file(filename: str, text: str) -> str:
"""Write text to a file
@@ -161,7 +163,7 @@ def write_to_file(filename: str, text: str) -> str:
return f"Error: {str(e)}"
-@command("append_to_file", "Append to file", '"file": "<file>", "text": "<text>"')
+@command("append_to_file", "Append to file", '"filename": "<filename>", "text": "<text>"')
def append_to_file(filename: str, text: str, shouldLog: bool = True) -> str:
"""Append text to a file
@@ -185,7 +187,7 @@ def append_to_file(filename: str, text: str, shouldLog: bool = True) -> str:
return f"Error: {str(e)}"
-@command("delete_file", "Delete file", '"file": "<file>"')
+@command("delete_file", "Delete file", '"filename": "<filename>"')
def delete_file(filename: str) -> str:
"""Delete a file
@@ -233,6 +235,8 @@ def search_files(directory: str) -> list[str]:
return found_files
+
+@command("download_file", "Search Files", '"url": "<url>", "filename": "<filename>"', CFG.allow_downloads, "Error: You do not have user authorization to download files locally.")
def download_file(url, filename):
"""Downloads a file
Args:
diff --git a/autogpt/commands/git_operations.py b/autogpt/commands/git_operations.py
index 0536152bb8..1fb99e5b2e 100644
--- a/autogpt/commands/git_operations.py
+++ b/autogpt/commands/git_operations.py
@@ -11,24 +11,24 @@ CFG = Config()
@command(
"clone_repository",
"Clone Repositoryy",
- '"repository_url": "<url>", "clone_path": "<directory>"',
+ '"repository_url": "<repository_url>", "clone_path": "<clone_path>"',
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:
+def clone_repository(repository_url: str, clone_path: str) -> str:
"""Clone a GitHub repository locally
Args:
- repo_url (str): The URL of the repository to clone
+ repository_url (str): The URL of the repository to clone
clone_path (str): The path to clone the repository to
Returns:
str: The result of the clone operation"""
- split_url = repo_url.split("//")
+ split_url = repository_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, safe_clone_path)
- return f"""Cloned {repo_url} to {safe_clone_path}"""
+ return f"""Cloned {repository_url} to {safe_clone_path}"""
except Exception as e:
return f"Error: {str(e)}"
diff --git a/autogpt/commands/google_search.py b/autogpt/commands/google_search.py
index 85eeae65bb..fcc1a9f4fa 100644
--- a/autogpt/commands/google_search.py
+++ b/autogpt/commands/google_search.py
@@ -11,7 +11,7 @@ from autogpt.config import Config
CFG = Config()
-@command("google", "Google Search", '"query": "<search>"', not CFG.google_api_key)
+@command("google", "Google Search", '"query": "<query>"', not CFG.google_api_key)
def google_search(query: str, num_results: int = 8) -> str:
"""Return the results of a Google search
@@ -40,7 +40,7 @@ def google_search(query: str, num_results: int = 8) -> str:
@command(
"google",
"Google Search",
- '"query": "<search>"',
+ '"query": "<query>"',
bool(CFG.google_api_key),
"Configure google_api_key.",
)
diff --git a/autogpt/commands/twitter.py b/autogpt/commands/twitter.py
index 8e64b21357..f0502271c7 100644
--- a/autogpt/commands/twitter.py
+++ b/autogpt/commands/twitter.py
@@ -12,7 +12,7 @@ load_dotenv()
@command(
"send_tweet",
"Send Tweet",
- '"text": "<text>"',
+ '"tweet_text": "<tweet_text>"',
)
def send_tweet(tweet_text: str) -> str:
"""
diff --git a/autogpt/config/ai_config.py b/autogpt/config/ai_config.py
index af387f0bdc..292978a417 100644
--- a/autogpt/config/ai_config.py
+++ b/autogpt/config/ai_config.py
@@ -12,6 +12,9 @@ import yaml
from autogpt.prompts.generator import PromptGenerator
+# Soon this will go in a folder where it remembers more stuff about the run(s)
+SAVE_FILE = str(Path(os.getcwd()) / "ai_settings.yaml")
+
class AIConfig:
"""
@@ -44,8 +47,6 @@ class AIConfig:
self.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"
@staticmethod
def load(config_file: str = SAVE_FILE) -> "AIConfig":
diff --git a/autogpt/llm_utils.py b/autogpt/llm_utils.py
index d26fb2d699..8b85959cdb 100644
--- a/autogpt/llm_utils.py
+++ b/autogpt/llm_utils.py
@@ -83,12 +83,14 @@ def create_chat_completion(
temperature=temperature,
max_tokens=max_tokens,
):
- return plugin.handle_chat_completion(
+ message = plugin.handle_chat_completion(
messages=messages,
model=model,
temperature=temperature,
max_tokens=max_tokens,
)
+ if message is not None:
+ return message
response = None
for attempt in range(num_retries):
backoff = 2 ** (attempt + 2)
diff --git a/autogpt/models/base_open_ai_plugin.py b/autogpt/models/base_open_ai_plugin.py
index 987e7aad5f..046295c0dc 100644
--- a/autogpt/models/base_open_ai_plugin.py
+++ b/autogpt/models/base_open_ai_plugin.py
@@ -34,7 +34,7 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):
def on_response(self, response: str, *args, **kwargs) -> str:
"""This method is called when a response is received from the model."""
- pass
+ return response
def can_handle_post_prompt(self) -> bool:
"""This method is called to check that the plugin can
@@ -51,7 +51,7 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):
Returns:
PromptGenerator: The prompt generator.
"""
- pass
+ return prompt
def can_handle_on_planning(self) -> bool:
"""This method is called to check that the plugin can
@@ -84,7 +84,7 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):
Returns:
str: The resulting response.
"""
- pass
+ return response
def can_handle_pre_instruction(self) -> bool:
"""This method is called to check that the plugin can
@@ -100,7 +100,7 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):
Returns:
List[Message]: The resulting list of messages.
"""
- pass
+ return messages
def can_handle_on_instruction(self) -> bool:
"""This method is called to check that the plugin can
@@ -132,7 +132,7 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):
Returns:
str: The resulting response.
"""
- pass
+ return response
def can_handle_pre_command(self) -> bool:
"""This method is called to check that the plugin can
@@ -151,7 +151,7 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):
Returns:
Tuple[str, Dict[str, Any]]: The command name and the arguments.
"""
- pass
+ return command_name, arguments
def can_handle_post_command(self) -> bool:
"""This method is called to check that the plugin can
@@ -168,7 +168,7 @@ class BaseOpenAIPlugin(AutoGPTPluginTemplate):
Returns:
str: The resulting response.
"""
- pass
+ return response
def can_handle_chat_completion(
self, messages: Dict[Any, Any], model: str, temperature: float, max_tokens: int
diff --git a/autogpt/prompts/prompt.py b/autogpt/prompts/prompt.py
index ba04263e05..e25ea7457f 100644
--- a/autogpt/prompts/prompt.py
+++ b/autogpt/prompts/prompt.py
@@ -71,7 +71,9 @@ def build_default_prompt_generator() -> PromptGenerator:
"Every command has a cost, so be smart and efficient. Aim to complete tasks in"
" the least number of steps."
)
-
+ prompt_generator.add_performance_evaluation(
+ "Write all code to a file."
+ )
return prompt_generator
diff --git a/autogpt/utils.py b/autogpt/utils.py
index e93d5ac740..dffd066268 100644
--- a/autogpt/utils.py
+++ b/autogpt/utils.py
@@ -3,7 +3,7 @@ import os
import requests
import yaml
from colorama import Fore
-from git import Repo
+from git.repo import Repo
def clean_input(prompt: str = ""):
diff --git a/requirements.txt b/requirements.txt
index b504c68461..2052a9ace7 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -31,7 +31,6 @@ pre-commit
black
isort
gitpython==3.1.31
-abstract-singleton
auto-gpt-plugin-template
# Items below this point will not be included in the Docker Image
@@ -48,5 +47,3 @@ pytest-mock
# OpenAI and Generic plugins import
openapi-python-client==0.13.4
-abstract-singleton
-auto-gpt-plugin-template