From 45610d1017bf3ce75be8f83771733aa536410c11 Mon Sep 17 00:00:00 2001 From: Luke <2609441+lc0rp@users.noreply.github.com> Date: Wed, 31 May 2023 15:10:34 -0400 Subject: [PATCH] Fixing abstract errors due to updated template. --- .../__init__.py | 88 ++++++++++++++++--- .../test_interactive_shell_commands.py | 36 +++++++- 2 files changed, 109 insertions(+), 15 deletions(-) diff --git a/src/autogpt_interactive_shell_commands_plugin/__init__.py b/src/autogpt_interactive_shell_commands_plugin/__init__.py index 1d2d12d..8a4e34e 100644 --- a/src/autogpt_interactive_shell_commands_plugin/__init__.py +++ b/src/autogpt_interactive_shell_commands_plugin/__init__.py @@ -13,34 +13,40 @@ class Message(TypedDict): + """Message type.""" + role: str content: str class AutoGPTInteractiveShellCommandsPlugin(AutoGPTPluginTemplate): """ - Interactive Shell Commands allows Auto-GPT to execute interactive shell commands and get feedback from the user." + Interactive Shell Commands allows Auto-GPT to execute interactive shell commands and get + feedback from the user." Build by @lcOrp on github. """ - + + # Default timeout in seconds (15 minutes) + _default_timeout_seconds: int = 900 + def __init__(self): """Initialize the plugin.""" super().__init__() self._name = "Auto-GPT-Interactive-Shell-Commands-Plugin" - self._version = "0.3.0" - self._description = f"This plugin allows Auto-GPT to execute interactive shell commands and get feedback from the user. For help and discussion: https://discord.com/channels/1092243196446249134/1109480174321414214" + self._version = "0.3.1" + self._description = ( + "This plugin allows Auto-GPT to execute interactive shell commands and get feedback" + "from the user. For help and discussion: " + "https://discord.com/channels/1092243196446249134/1109480174321414214" + ) # Default timeout in seconds (15 minutes) - self._default_timeout_seconds = os.getenv( - "INTERACTIVE_SHELL_DEFAULT_TIMEOUT_SECONDS", 900 - ) + self._default_timeout_seconds = os.getenv("INTERACTIVE_SHELL_DEFAULT_TIMEOUT_SECONDS", self._default_timeout_seconds) # Print out a summary of the settings - print( - f"Auto-GPT Interactive Shell Commands Plugin Settings (v {self._version}):" - ) - print("=====================================================================") + print(f"Interactive Shell Commands Plugin Settings (v {self._version}):") + print("=================================================================") print(f" - Default Timeout: {self._default_timeout_seconds} seconds") def post_prompt(self, prompt: PromptGenerator) -> PromptGenerator: @@ -105,7 +111,6 @@ def can_handle_on_response(self) -> bool: def on_response(self, response: str, *args, **kwargs) -> Optional[str]: """This method is called when a response is received from the model.""" - pass def can_handle_on_planning(self) -> bool: """ @@ -235,7 +240,7 @@ def pre_command( Tuple[str, Dict[str, Any]]: The command name and the arguments. """ # Return "write_to_file" => settings file - pass + return command_name, arguments def can_handle_post_command(self) -> bool: """ @@ -257,7 +262,7 @@ def post_command(self, command_name: str, response: str) -> str: 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 @@ -291,4 +296,59 @@ def handle_chat_completion( Returns: str: The resulting response. """ + + def can_handle_text_embedding(self, text: str) -> bool: + """This method is called to check that the plugin can + handle the text_embedding method. + Args: + text (str): The text to be convert to embedding. + Returns: + bool: True if the plugin can handle the text_embedding method.""" + return False + + def handle_text_embedding(self, text: str) -> list: + """This method is called when the chat completion is done. + Args: + text (str): The text to be convert to embedding. + Returns: + list: The text embedding. + """ + pass + + def can_handle_user_input(self, user_input: str) -> bool: + """This method is called to check that the plugin can + handle the user_input method. + + Args: + user_input (str): The user input. + + Returns: + bool: True if the plugin can handle the user_input method.""" + return False + + def user_input(self, user_input: str) -> str: + """This method is called to request user input to the user. + + Args: + user_input (str): The question or prompt to ask the user. + + Returns: + str: The user input. + """ + pass + + def can_handle_report(self) -> bool: + """This method is called to check that the plugin can + handle the report method. + + Returns: + bool: True if the plugin can handle the report method.""" + return False + + def report(self, message: str) -> None: + """This method is called to report a message to the user. + + Args: + message (str): The message to report. + """ pass diff --git a/src/autogpt_interactive_shell_commands_plugin/test_interactive_shell_commands.py b/src/autogpt_interactive_shell_commands_plugin/test_interactive_shell_commands.py index 3774ec7..5be41d5 100644 --- a/src/autogpt_interactive_shell_commands_plugin/test_interactive_shell_commands.py +++ b/src/autogpt_interactive_shell_commands_plugin/test_interactive_shell_commands.py @@ -1,8 +1,14 @@ +""" +Tests for the InteractiveShellCommands class. +""" from unittest.mock import patch -from .interactive_shell_commands import InteractiveShellCommands +from . import AutoGPTInteractiveShellCommandsPlugin +from .interactive_shell_commands import InteractiveShellCommands +from auto_gpt_plugin_template import AutoGPTPluginTemplate def test_ask_user() -> None: + """ Test that the ask_user method returns the expected responses.""" prompts = ["Question 1: ", "Question 2: ", "Question 3: "] expected_responses = ["Answer 1", "Answer 2", "Answer 3"] with patch("inputimeout.inputimeout", side_effect=expected_responses): @@ -15,6 +21,7 @@ def test_ask_user() -> None: def test_ask_user_timeout() -> None: + """ Test that the ask_user method returns the expected responses when a timeout occurs.""" prompts = ["Prompt 1:"] timeout = 5 @@ -25,3 +32,30 @@ def test_ask_user_timeout() -> None: responses = is_commands.ask_user(prompts, timeout) assert responses == [f"Timeout after {timeout} seconds"] + + +def test_auto_gpt_interactive_shell_commands_plugin(): + plugin = AutoGPTInteractiveShellCommandsPlugin() + + assert isinstance(plugin, AutoGPTPluginTemplate) + assert plugin._name == "Auto-GPT-Interactive-Shell-Commands-Plugin" + + assert plugin.can_handle_post_prompt() is True + assert plugin.can_handle_on_response() is False + assert plugin.can_handle_on_planning() is False + assert plugin.can_handle_post_planning() is False + assert plugin.can_handle_pre_instruction() is False + assert plugin.can_handle_on_instruction() is False + assert plugin.can_handle_post_instruction() is False + assert plugin.can_handle_pre_command() is False + assert plugin.can_handle_post_command() is False + messages = [] + model = None + temperature = 1.0 + max_tokens = 10 + assert plugin.can_handle_chat_completion(messages, model, temperature, max_tokens) is False + text = "" + assert plugin.can_handle_text_embedding(text) is False + user_input = "" + assert plugin.can_handle_user_input(user_input) is False + assert plugin.can_handle_report() is False \ No newline at end of file