Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Fixing abstract errors due to updated template.
Browse files Browse the repository at this point in the history
  • Loading branch information
lc0rp committed May 31, 2023
1 parent 2d2d4b5 commit 45610d1
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 15 deletions.
88 changes: 74 additions & 14 deletions src/autogpt_interactive_shell_commands_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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

Expand All @@ -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

0 comments on commit 45610d1

Please sign in to comment.