From 2cca2e78ef6bc43135dfe92c2d58dfe27c05c3da Mon Sep 17 00:00:00 2001 From: Torantulino Date: Tue, 28 Mar 2023 23:54:06 +0100 Subject: [PATCH] Changes user input from typed input to keypress. --- AutonomousAI/main.py | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/AutonomousAI/main.py b/AutonomousAI/main.py index 7aa62f7f..e3220ecc 100644 --- a/AutonomousAI/main.py +++ b/AutonomousAI/main.py @@ -4,6 +4,7 @@ import json import keys import commands as cmd import memory as mem +import keyboard # Initialize the OpenAI API client openai.api_key = keys.OPENAI_API_KEY @@ -55,6 +56,8 @@ def chat_with_ai(prompt, user_input, full_message_history, permanent_memory, tok model="gpt-4", messages=current_context, ) + print("---------------------------") + assistant_reply = response.choices[0].message["content"] return assistant_reply @@ -173,25 +176,41 @@ ACCOUNTS: 4. Substack: entrepreneurgpt@gmail.com""" token_limit = 6000 # The maximum number of tokens allowed in the API call result = None -# Example loop for interaction -# Example loop for interaction -while True: - user_input = input("User: ") - if user_input.lower() == "exit": +# Interaction Loop +while True: + # Get key press: Prompt the user to press enter to continue or escape to exit + print("Press 'Enter' to continue or 'Escape' to exit...") + user_input = "" + + while True: + if keyboard.is_pressed('enter'): + user_input = "NEXT COMMAND" + break + elif keyboard.is_pressed('escape'): + user_input = "EXIT" + break + else: + continue + + if user_input != "NEXT COMMAND": + print("Exiting...") break - # Check if there's a result from the previous iteration and append it to the message history - if result != None: - full_message_history.append(create_chat_message("system", result)) - print("system: " + result) + print("-=-=-=-=-=-=-= NEXT COMMAND AUTHORISED -=-=-=-=-=-=-=") + # Send command to AI, get response assistant_reply = chat_with_ai(prompt, user_input, full_message_history, mem.permanent_memory, token_limit) print(f"Assistant: {assistant_reply}") - print("-------------------------") - # Add user message and assistant reply to message history + # Update full message history full_message_history.append(create_chat_message("user", user_input)) full_message_history.append(create_chat_message("assistant", assistant_reply)) result = execute_command(assistant_reply) + + # Check if there's a result append it to the message history + if result != None: + full_message_history.append(create_chat_message("system", result)) + print("system: " + result) +