diff --git a/sources/agents/casual_agent.py b/sources/agents/casual_agent.py index b603317..1d5467f 100644 --- a/sources/agents/casual_agent.py +++ b/sources/agents/casual_agent.py @@ -27,13 +27,13 @@ class CasualAgent(Agent): self.wait_message(speech_module) while not complete: - if exec_success: - complete = True animate_thinking("Thinking...", color="status") answer, reasoning = self.llm_request() exec_success, _ = self.execute_modules(answer) answer = self.remove_blocks(answer) self.last_answer = answer + if exec_success: + complete = True return answer, reasoning if __name__ == "__main__": diff --git a/sources/agents/code_agent.py b/sources/agents/code_agent.py index ca49b7f..13e2d20 100644 --- a/sources/agents/code_agent.py +++ b/sources/agents/code_agent.py @@ -32,6 +32,7 @@ class CoderAgent(Agent): animate_thinking("Thinking...", color="status") self.wait_message(speech_module) answer, reasoning = self.llm_request() + animate_thinking("Executing code...", color="status") exec_success, _ = self.execute_modules(answer) answer = self.remove_blocks(answer) self.last_answer = answer diff --git a/sources/router.py b/sources/router.py index 8db0ec3..2ebd991 100644 --- a/sources/router.py +++ b/sources/router.py @@ -80,7 +80,7 @@ if __name__ == "__main__": Hey could you search the web for the latest news on the stock market ? """, """ - hey can you give dating advice ? + hey can you give give a list of the files in the current directory ? """, """ Make a cool game to illustrate the current relation between USA and europe diff --git a/sources/text_to_speech.py b/sources/text_to_speech.py index 13ba1a4..6bc4527 100644 --- a/sources/text_to_speech.py +++ b/sources/text_to_speech.py @@ -40,8 +40,7 @@ class Speech(): ) for i, (gs, ps, audio) in enumerate(generator): audio_file = 'sample.wav' - print(audio_file) - display(Audio(data=audio, rate=24000, autoplay=i==0)) + display(Audio(data=audio, rate=24000, autoplay=i==0), display_id=False) sf.write(audio_file, audio, 24000) # save each audio file if platform.system().lower() != "windows": subprocess.call(["afplay", audio_file]) diff --git a/sources/tools/PyInterpreter.py b/sources/tools/PyInterpreter.py index 8d47bda..2c250c9 100644 --- a/sources/tools/PyInterpreter.py +++ b/sources/tools/PyInterpreter.py @@ -1,5 +1,6 @@ import sys +import os import re from io import StringIO @@ -25,10 +26,15 @@ class PyInterpreter(Tools): return "Code rejected by user." stdout_buffer = StringIO() sys.stdout = stdout_buffer + global_vars = { + '__builtins__': __builtins__, + 'os': os, + 'sys': sys, + } code = '\n\n'.join(codes) try: try: - buffer = exec(code) + buffer = exec(code, global_vars) if buffer is not None: output = buffer + '\n' except Exception as e: diff --git a/sources/utility.py b/sources/utility.py index 7b7d696..a9a29c0 100644 --- a/sources/utility.py +++ b/sources/utility.py @@ -2,6 +2,9 @@ from colorama import Fore from termcolor import colored import platform +import threading +import itertools +import time def pretty_print(text, color = "info"): @@ -49,44 +52,41 @@ def pretty_print(text, color = "info"): color = "default" print(colored(text, color_map[color])) -def animate_thinking(text="thinking...", color="status", duration=2): +def animate_thinking(text, color="status", duration=2): """ - Display an animated "thinking..." indicator. - + Display an animated "thinking..." indicator in a separate thread. Args: - text (str): Text to display (default: "thinking...") - color (str): Color for the text (matches pretty_print colors) + text (str): Text to display + color (str): Color for the text duration (float): How long to animate in seconds """ - import time - import itertools + def _animate(): + color_map = { + "success": (Fore.GREEN, "green"), + "failure": (Fore.RED, "red"), + "status": (Fore.LIGHTGREEN_EX, "light_green"), + "code": (Fore.LIGHTBLUE_EX, "light_blue"), + "warning": (Fore.YELLOW, "yellow"), + "output": (Fore.LIGHTCYAN_EX, "cyan"), + "default": (Fore.RESET, "black"), + "info": (Fore.CYAN, "cyan") + } - color_map = { - "success": (Fore.GREEN, "green"), - "failure": (Fore.RED, "red"), - "status": (Fore.LIGHTGREEN_EX, "light_green"), - "code": (Fore.LIGHTBLUE_EX, "light_blue"), - "warning": (Fore.YELLOW, "yellow"), - "output": (Fore.LIGHTCYAN_EX, "cyan"), - "default": (Fore.RESET, "black"), - "info": (Fore.CYAN, "cyan") - } + fore_color, term_color = color_map[color] + spinner = itertools.cycle(['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']) + end_time = time.time() + duration - if color not in color_map: - color = "info" - - fore_color, term_color = color_map[color] - spinner = itertools.cycle(['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']) - end_time = time.time() + duration - - while time.time() < end_time: - symbol = next(spinner) - if platform.system().lower() != "windows": - print(f"\r{fore_color}{symbol} {text}{Fore.RESET}", end="", flush=True) - else: - print(colored(f"\r{symbol} {text}", term_color), end="", flush=True) - time.sleep(0.1) - print() + while time.time() < end_time: + symbol = next(spinner) + if platform.system().lower() != "windows": + print(f"\r{fore_color}{symbol} {text}{Fore.RESET}", end="", flush=True) + else: + print(colored(f"\r{symbol} {text}", term_color), end="", flush=True) + time.sleep(0.1) + print() + animation_thread = threading.Thread(target=_animate) + animation_thread.daemon = True + animation_thread.start() def timer_decorator(func): """