Skip to content

Commit

Permalink
Chat plugin capability (Significant-Gravitas#2929)
Browse files Browse the repository at this point in the history
Co-authored-by: BillSchumacher <[email protected]>
  • Loading branch information
Wladastic and BillSchumacher authored Apr 26, 2023
1 parent a0cfdb0 commit cd8fdb3
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 25 additions & 5 deletions autogpt/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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


Expand Down Expand Up @@ -84,8 +84,11 @@ def start_interaction_loop(self):
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(
Expand Down Expand Up @@ -114,6 +117,8 @@ def start_interaction_loop(self):
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:
Expand All @@ -123,6 +128,11 @@ def start_interaction_loop(self):
# ### 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,
Expand All @@ -136,9 +146,13 @@ def start_interaction_loop(self):
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
Expand Down Expand Up @@ -193,10 +207,16 @@ def start_interaction_loop(self):
"",
)
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,
Expand Down
2 changes: 2 additions & 0 deletions autogpt/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def __init__(self) -> None:
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")

Expand Down
3 changes: 3 additions & 0 deletions autogpt/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from autogpt.singleton import Singleton
from autogpt.speech import say_text
from autogpt.utils import send_chat_message_to_user


class Logger(metaclass=Singleton):
Expand Down Expand Up @@ -84,6 +85,8 @@ def typewriter_log(
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)
Expand Down
50 changes: 48 additions & 2 deletions autogpt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,56 @@
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...")
Expand Down

0 comments on commit cd8fdb3

Please sign in to comment.