Fix : major displaying issues and libraries warning

This commit is contained in:
martin legrand 2025-03-11 11:45:02 +01:00
parent 60e740f605
commit ed02a4dad0
6 changed files with 44 additions and 38 deletions

View File

@ -27,13 +27,13 @@ class CasualAgent(Agent):
self.wait_message(speech_module) self.wait_message(speech_module)
while not complete: while not complete:
if exec_success:
complete = True
animate_thinking("Thinking...", color="status") animate_thinking("Thinking...", color="status")
answer, reasoning = self.llm_request() answer, reasoning = self.llm_request()
exec_success, _ = self.execute_modules(answer) exec_success, _ = self.execute_modules(answer)
answer = self.remove_blocks(answer) answer = self.remove_blocks(answer)
self.last_answer = answer self.last_answer = answer
if exec_success:
complete = True
return answer, reasoning return answer, reasoning
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -32,6 +32,7 @@ class CoderAgent(Agent):
animate_thinking("Thinking...", color="status") animate_thinking("Thinking...", color="status")
self.wait_message(speech_module) self.wait_message(speech_module)
answer, reasoning = self.llm_request() answer, reasoning = self.llm_request()
animate_thinking("Executing code...", color="status")
exec_success, _ = self.execute_modules(answer) exec_success, _ = self.execute_modules(answer)
answer = self.remove_blocks(answer) answer = self.remove_blocks(answer)
self.last_answer = answer self.last_answer = answer

View File

@ -80,7 +80,7 @@ if __name__ == "__main__":
Hey could you search the web for the latest news on the stock market ? 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 Make a cool game to illustrate the current relation between USA and europe

View File

@ -40,8 +40,7 @@ class Speech():
) )
for i, (gs, ps, audio) in enumerate(generator): for i, (gs, ps, audio) in enumerate(generator):
audio_file = 'sample.wav' audio_file = 'sample.wav'
print(audio_file) display(Audio(data=audio, rate=24000, autoplay=i==0), display_id=False)
display(Audio(data=audio, rate=24000, autoplay=i==0))
sf.write(audio_file, audio, 24000) # save each audio file sf.write(audio_file, audio, 24000) # save each audio file
if platform.system().lower() != "windows": if platform.system().lower() != "windows":
subprocess.call(["afplay", audio_file]) subprocess.call(["afplay", audio_file])

View File

@ -1,5 +1,6 @@
import sys import sys
import os
import re import re
from io import StringIO from io import StringIO
@ -25,10 +26,15 @@ class PyInterpreter(Tools):
return "Code rejected by user." return "Code rejected by user."
stdout_buffer = StringIO() stdout_buffer = StringIO()
sys.stdout = stdout_buffer sys.stdout = stdout_buffer
global_vars = {
'__builtins__': __builtins__,
'os': os,
'sys': sys,
}
code = '\n\n'.join(codes) code = '\n\n'.join(codes)
try: try:
try: try:
buffer = exec(code) buffer = exec(code, global_vars)
if buffer is not None: if buffer is not None:
output = buffer + '\n' output = buffer + '\n'
except Exception as e: except Exception as e:

View File

@ -2,6 +2,9 @@
from colorama import Fore from colorama import Fore
from termcolor import colored from termcolor import colored
import platform import platform
import threading
import itertools
import time
def pretty_print(text, color = "info"): def pretty_print(text, color = "info"):
@ -49,18 +52,15 @@ def pretty_print(text, color = "info"):
color = "default" color = "default"
print(colored(text, color_map[color])) 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: Args:
text (str): Text to display (default: "thinking...") text (str): Text to display
color (str): Color for the text (matches pretty_print colors) color (str): Color for the text
duration (float): How long to animate in seconds duration (float): How long to animate in seconds
""" """
import time def _animate():
import itertools
color_map = { color_map = {
"success": (Fore.GREEN, "green"), "success": (Fore.GREEN, "green"),
"failure": (Fore.RED, "red"), "failure": (Fore.RED, "red"),
@ -72,9 +72,6 @@ def animate_thinking(text="thinking...", color="status", duration=2):
"info": (Fore.CYAN, "cyan") "info": (Fore.CYAN, "cyan")
} }
if color not in color_map:
color = "info"
fore_color, term_color = color_map[color] fore_color, term_color = color_map[color]
spinner = itertools.cycle(['', '', '', '', '', '', '', '', '', '']) spinner = itertools.cycle(['', '', '', '', '', '', '', '', '', ''])
end_time = time.time() + duration end_time = time.time() + duration
@ -87,6 +84,9 @@ def animate_thinking(text="thinking...", color="status", duration=2):
print(colored(f"\r{symbol} {text}", term_color), end="", flush=True) print(colored(f"\r{symbol} {text}", term_color), end="", flush=True)
time.sleep(0.1) time.sleep(0.1)
print() print()
animation_thread = threading.Thread(target=_animate)
animation_thread.daemon = True
animation_thread.start()
def timer_decorator(func): def timer_decorator(func):
""" """