Chat plugin capability (#2929)

Co-authored-by: BillSchumacher <34168009+BillSchumacher@users.noreply.github.com>
This commit is contained in:
WladBlank
2023-04-26 22:08:39 +02:00
committed by GitHub
parent a0cfdb0830
commit cd8fdb31ef
5 changed files with 84 additions and 7 deletions

View File

@@ -201,3 +201,9 @@ OPENAI_API_KEY=your-openai-api-key
#ALLOWLISTED_PLUGINS - Sets the listed plugins that are allowed (Example: plugin1,plugin2,plugin3)
ALLOWLISTED_PLUGINS=
################################################################################
### CHAT PLUGIN SETTINGS
################################################################################
# CHAT_MESSAGES_ENABLED - Enable chat messages (Default: False)
# CHAT_MESSAGES_ENABLED=False

View File

@@ -9,7 +9,7 @@ from autogpt.llm_utils import create_chat_completion
from autogpt.logs import logger, print_assistant_thoughts
from autogpt.speech import say_text
from autogpt.spinner import Spinner
from autogpt.utils import clean_input
from autogpt.utils import clean_input, send_chat_message_to_user
from autogpt.workspace import Workspace
@@ -84,8 +84,11 @@ class Agent:
logger.typewriter_log(
"Continuous Limit Reached: ", Fore.YELLOW, f"{cfg.continuous_limit}"
)
send_chat_message_to_user(
f"Continuous Limit Reached: \n {cfg.continuous_limit}"
)
break
send_chat_message_to_user("Thinking... \n")
# Send message to AI, get response
with Spinner("Thinking... "):
assistant_reply = chat_with_ai(
@@ -114,6 +117,8 @@ class Agent:
command_name, arguments = get_command(assistant_reply_json)
if cfg.speak_mode:
say_text(f"I want to execute {command_name}")
send_chat_message_to_user("Thinking... \n")
arguments = self._resolve_pathlike_command_args(arguments)
except Exception as e:
@@ -123,6 +128,11 @@ class Agent:
# ### GET USER AUTHORIZATION TO EXECUTE COMMAND ###
# Get key press: Prompt the user to press enter to continue or escape
# to exit
self.user_input = ""
send_chat_message_to_user(
"NEXT ACTION: \n " + f"COMMAND = {command_name} \n "
f"ARGUMENTS = {arguments}"
)
logger.typewriter_log(
"NEXT ACTION: ",
Fore.CYAN,
@@ -136,9 +146,13 @@ class Agent:
flush=True,
)
while True:
console_input = clean_input(
Fore.MAGENTA + "Input:" + Style.RESET_ALL
)
console_input = ""
if cfg.chat_messages_enabled:
console_input = clean_input("Waiting for your response...")
else:
console_input = clean_input(
Fore.MAGENTA + "Input:" + Style.RESET_ALL
)
if console_input.lower().strip() == "y":
user_input = "GENERATE NEXT COMMAND JSON"
break
@@ -193,10 +207,16 @@ class Agent:
"",
)
elif user_input == "EXIT":
send_chat_message_to_user("Exiting...")
print("Exiting...", flush=True)
break
else:
# Print command
send_chat_message_to_user(
"NEXT ACTION: \n " + f"COMMAND = {command_name} \n "
f"ARGUMENTS = {arguments}"
)
logger.typewriter_log(
"NEXT ACTION: ",
Fore.CYAN,

View File

@@ -61,6 +61,8 @@ class Config(metaclass=Singleton):
self.use_mac_os_tts = False
self.use_mac_os_tts = os.getenv("USE_MAC_OS_TTS")
self.chat_messages_enabled = os.getenv("CHAT_MESSAGES_ENABLED") == "True"
self.use_brian_tts = False
self.use_brian_tts = os.getenv("USE_BRIAN_TTS")

View File

@@ -12,6 +12,7 @@ from colorama import Fore, Style
from autogpt.singleton import Singleton
from autogpt.speech import say_text
from autogpt.utils import send_chat_message_to_user
class Logger(metaclass=Singleton):
@@ -84,6 +85,8 @@ class Logger(metaclass=Singleton):
if speak_text and self.speak_mode:
say_text(f"{title}. {content}")
send_chat_message_to_user(f"{title}. {content}")
if content:
if isinstance(content, list):
content = " ".join(content)

View File

@@ -11,10 +11,56 @@ try:
except:
pass
from autogpt.config import Config
def clean_input(prompt: str = ""):
def send_chat_message_to_user(report: str):
cfg = Config()
if not cfg.chat_messages_enabled:
return
for plugin in cfg.plugins:
if not hasattr(plugin, "can_handle_report"):
continue
if not plugin.can_handle_report():
continue
plugin.report(report)
def clean_input(prompt: str = "", talk=False):
try:
return input(prompt)
cfg = Config()
if cfg.chat_messages_enabled:
for plugin in cfg.plugins:
if not hasattr(plugin, "can_handle_user_input"):
continue
if not plugin.can_handle_user_input(user_input=prompt):
continue
plugin_response = plugin.user_input(user_input=prompt)
if not plugin_response:
continue
if plugin_response.lower() in [
"yes",
"yeah",
"y",
"ok",
"okay",
"sure",
"alright",
]:
return "y"
elif plugin_response.lower() in [
"no",
"nope",
"n",
"negative",
]:
return "n"
return plugin_response
# ask for input, default when just pressing Enter is y
print("Asking user via keyboard...")
answer = input(prompt)
return answer
except KeyboardInterrupt:
print("You interrupted Auto-GPT")
print("Quitting...")