mirror of
https://github.com/tcsenpai/agenticSeek.git
synced 2025-06-06 11:05:26 +00:00
feat : better verbose message
This commit is contained in:
parent
8c431c690e
commit
7331cb7cb2
@ -22,13 +22,14 @@ class OllamaLLM(GeneratorLLM):
|
||||
stream = ollama.chat(
|
||||
model=self.model,
|
||||
messages=history,
|
||||
stream=True,
|
||||
stream=False,
|
||||
)
|
||||
|
||||
for chunk in stream:
|
||||
content = chunk['message']['content']
|
||||
if '\n' in content:
|
||||
self.logger.info(content)
|
||||
if '.' in content:
|
||||
self.logger.info(self.state.current_buffer)
|
||||
self.state.last_complete_sentence = self.state.current_buffer
|
||||
|
||||
with self.state.lock:
|
||||
self.state.current_buffer += content
|
||||
|
@ -19,7 +19,7 @@ import sys
|
||||
import re
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from sources.utility import pretty_print
|
||||
from sources.utility import pretty_print, animate_thinking
|
||||
|
||||
def get_chrome_path() -> str:
|
||||
if sys.platform.startswith("win"):
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
from sources.text_to_speech import Speech
|
||||
from sources.utility import pretty_print
|
||||
from sources.utility import pretty_print, animate_thinking
|
||||
from sources.router import AgentRouter
|
||||
from sources.speech_to_text import AudioTranscriber, AudioRecorder
|
||||
|
||||
@ -12,23 +12,37 @@ class Interaction:
|
||||
tts_enabled: bool = True,
|
||||
stt_enabled: bool = True,
|
||||
recover_last_session: bool = False):
|
||||
self.agents = agents
|
||||
self.current_agent = None
|
||||
self.router = AgentRouter(self.agents)
|
||||
self.speech = Speech(enable=tts_enabled)
|
||||
self.is_active = True
|
||||
self.current_agent = None
|
||||
self.last_query = None
|
||||
self.last_answer = None
|
||||
self.ai_name = self.find_ai_name()
|
||||
self.speech = None
|
||||
self.agents = agents
|
||||
self.tts_enabled = tts_enabled
|
||||
self.stt_enabled = stt_enabled
|
||||
self.recover_last_session = recover_last_session
|
||||
self.router = AgentRouter(self.agents)
|
||||
if tts_enabled:
|
||||
animate_thinking("Initializing text-to-speech...", color="status")
|
||||
self.speech = Speech(enable=tts_enabled)
|
||||
self.ai_name = self.find_ai_name()
|
||||
self.transcriber = None
|
||||
self.recorder = None
|
||||
if stt_enabled:
|
||||
animate_thinking("Initializing speech recognition...", color="status")
|
||||
self.transcriber = AudioTranscriber(self.ai_name, verbose=False)
|
||||
self.recorder = AudioRecorder()
|
||||
if recover_last_session:
|
||||
self.load_last_session()
|
||||
if tts_enabled:
|
||||
self.emit_status()
|
||||
|
||||
def emit_status(self):
|
||||
"""Print the current status of agenticSeek."""
|
||||
if self.stt_enabled:
|
||||
pretty_print(f"Text-to-speech trigger is {self.ai_name}", color="status")
|
||||
if self.tts_enabled:
|
||||
self.speech.speak("Hello, we are online and ready. What can I do for you ?")
|
||||
pretty_print("AgenticSeek is ready.", color="status")
|
||||
|
||||
def find_ai_name(self) -> str:
|
||||
"""Find the name of the default AI. It is required for STT as a trigger word."""
|
||||
|
@ -6,8 +6,8 @@ import threading
|
||||
import itertools
|
||||
import time
|
||||
|
||||
global thinking_toggle
|
||||
thinking_toggle = False
|
||||
thinking_event = threading.Event()
|
||||
current_animation_thread = None
|
||||
|
||||
def get_color_map():
|
||||
if platform.system().lower() != "windows":
|
||||
@ -48,8 +48,11 @@ def pretty_print(text, color="info"):
|
||||
- "output": Cyan
|
||||
- "default": Black (Windows only)
|
||||
"""
|
||||
global thinking_toggle
|
||||
thinking_toggle = False
|
||||
thinking_event.set()
|
||||
if current_animation_thread and current_animation_thread.is_alive():
|
||||
current_animation_thread.join()
|
||||
thinking_event.clear()
|
||||
|
||||
color_map = get_color_map()
|
||||
if color not in color_map:
|
||||
color = "info"
|
||||
@ -61,10 +64,14 @@ def animate_thinking(text, color="status", duration=120):
|
||||
It use a daemon thread to run the animation. This will not block the main thread.
|
||||
Color are the same as pretty_print.
|
||||
"""
|
||||
global thinking_toggle
|
||||
thinking_toggle = True
|
||||
global current_animation_thread
|
||||
|
||||
thinking_event.set()
|
||||
if current_animation_thread and current_animation_thread.is_alive():
|
||||
current_animation_thread.join()
|
||||
thinking_event.clear()
|
||||
|
||||
def _animate():
|
||||
global thinking_toggle
|
||||
color_map = {
|
||||
"success": (Fore.GREEN, "green"),
|
||||
"failure": (Fore.RED, "red"),
|
||||
@ -84,10 +91,7 @@ def animate_thinking(text, color="status", duration=120):
|
||||
])
|
||||
end_time = time.time() + duration
|
||||
|
||||
while time.time() < end_time:
|
||||
if not thinking_toggle:
|
||||
# stop if another text is printed
|
||||
break
|
||||
while not thinking_event.is_set() and time.time() < end_time:
|
||||
symbol = next(spinner)
|
||||
if platform.system().lower() != "windows":
|
||||
print(f"\r{fore_color}{symbol} {text}{Fore.RESET}", end="", flush=True)
|
||||
@ -95,9 +99,8 @@ def animate_thinking(text, color="status", duration=120):
|
||||
print(f"\r{colored(f'{symbol} {text}', term_color)}", end="", flush=True)
|
||||
time.sleep(0.2)
|
||||
print("\r" + " " * (len(text) + 7) + "\r", end="", flush=True)
|
||||
print()
|
||||
animation_thread = threading.Thread(target=_animate, daemon=True)
|
||||
animation_thread.start()
|
||||
current_animation_thread = threading.Thread(target=_animate, daemon=True)
|
||||
current_animation_thread.start()
|
||||
|
||||
def timer_decorator(func):
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user