From 5f4e3173213e50cb2b306a9395d59a98bbac8a96 Mon Sep 17 00:00:00 2001 From: Richard Beales Date: Sat, 15 Apr 2023 18:24:57 +0100 Subject: [PATCH] Only add execute shell scripts to prompt if AI is allowed to do it. (#1551) --- autogpt/prompt.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/autogpt/prompt.py b/autogpt/prompt.py index 20492978eb74..5924ce0ca122 100644 --- a/autogpt/prompt.py +++ b/autogpt/prompt.py @@ -3,6 +3,7 @@ from autogpt.config.config import Config from autogpt.logs import logger from autogpt.promptgenerator import PromptGenerator +from autogpt.config import Config from autogpt.setup import prompt_user from autogpt.utils import clean_input @@ -18,6 +19,9 @@ def get_prompt() -> str: str: The generated prompt string. """ + # Initialize the Config object + cfg = Config() + # Initialize the PromptGenerator object prompt_generator = PromptGenerator() @@ -73,16 +77,27 @@ def get_prompt() -> str: {"code": "", "focus": ""}, ), ("Execute Python File", "execute_python_file", {"file": ""}), - ( - "Execute Shell Command, non-interactive commands only", - "execute_shell", - {"command_line": ""}, - ), - ("Task Complete (Shutdown)", "task_complete", {"reason": ""}), ("Generate Image", "generate_image", {"prompt": ""}), - ("Do Nothing", "do_nothing", {}), ] + # Only add shell command to the prompt if the AI is allowed to execute it + if cfg.execute_local_commands: + commands.append( + ( + "Execute Shell Command, non-interactive commands only", + "execute_shell", + {"command_line": ""}, + ), + ) + + # Add these command last. + commands.append( + ("Do Nothing", "do_nothing", {}), + ) + commands.append( + ("Task Complete (Shutdown)", "task_complete", {"reason": ""}), + ) + # Add commands to the PromptGenerator object for command_label, command_name, args in commands: prompt_generator.add_command(command_label, command_name, args)