diff --git a/AutonomousAI/main.py b/AutonomousAI/main.py index f2157042c0..7586c0348c 100644 --- a/AutonomousAI/main.py +++ b/AutonomousAI/main.py @@ -4,6 +4,7 @@ import memory as mem import data import chat from colorama import Fore, Style +from spinner import Spinner def print_assistant_thoughts(assistant_reply): try: @@ -53,7 +54,8 @@ user_input = "NEXT COMMAND" # Interaction Loop while True: # Send message to AI, get response - assistant_reply = chat.chat_with_ai(prompt, user_input, full_message_history, mem.permanent_memory, token_limit) + with Spinner("Thinking... "): + assistant_reply = chat.chat_with_ai(prompt, user_input, full_message_history, mem.permanent_memory, token_limit) # Print Assistant thoughts print_assistant_thoughts(assistant_reply) diff --git a/AutonomousAI/spinner.py b/AutonomousAI/spinner.py new file mode 100644 index 0000000000..ebb5fb9862 --- /dev/null +++ b/AutonomousAI/spinner.py @@ -0,0 +1,30 @@ +import sys +import threading +import itertools +import time + +class Spinner: + def __init__(self, message="Loading...", delay=0.1): + self.spinner = itertools.cycle(['-', '/', '|', '\\']) + self.delay = delay + self.message = message + self.running = False + self.spinner_thread = None + + def spin(self): + while self.running: + sys.stdout.write(next(self.spinner) + " " + self.message + "\r") + sys.stdout.flush() + time.sleep(self.delay) + sys.stdout.write('\b' * (len(self.message) + 2)) + + def __enter__(self): + self.running = True + self.spinner_thread = threading.Thread(target=self.spin) + self.spinner_thread.start() + + def __exit__(self, exc_type, exc_value, exc_traceback): + self.running = False + self.spinner_thread.join() + sys.stdout.write('\r' + ' ' * (len(self.message) + 2) + '\r') + sys.stdout.flush()