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