Adds spinner when AI is thinking
parent
71f9229f2f
commit
b054228769
|
@ -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)
|
||||
|
|
|
@ -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()
|
Loading…
Reference in New Issue