mirror of
https://github.com/tcsenpai/agenticSeek.git
synced 2025-06-05 02:25:27 +00:00
Feat : interaction class
This commit is contained in:
parent
62cc76764e
commit
55ccb408fc
44
main.py
44
main.py
@ -1,54 +1,40 @@
|
||||
#!/usr/bin python3
|
||||
|
||||
import sys
|
||||
from colorama import Fore
|
||||
import signal
|
||||
import argparse
|
||||
|
||||
from sources.text_to_speech import Speech
|
||||
from sources.code_agent import CoderAgent
|
||||
from sources.utility import pretty_print
|
||||
from sources.llm_provider import Provider
|
||||
from sources.interaction import Interaction
|
||||
from sources.code_agent import CoderAgent
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='Deepseek AI assistant')
|
||||
parser.add_argument('--speak', action='store_true',
|
||||
help='Make AI use text-to-speech')
|
||||
args = parser.parse_args()
|
||||
|
||||
def get_user_query() -> str:
|
||||
buffer = ""
|
||||
def handleInterrupt(signum, frame):
|
||||
sys.exit(0)
|
||||
|
||||
while buffer == "" or buffer.isascii() == False:
|
||||
buffer = input(f">>> ")
|
||||
if buffer == "exit":
|
||||
return None
|
||||
return buffer
|
||||
def main():
|
||||
signal.signal(signal.SIGINT, handler=handleInterrupt)
|
||||
|
||||
def conversation_loop():
|
||||
speech_module = Speech()
|
||||
#local_provider = Provider("ollama", "deepseek-r1:14b", None)
|
||||
server_provider = Provider("server", "deepseek-r1:14b", "192.168.1.100:5000")
|
||||
server_provider = Provider(provider_name="server",
|
||||
model="deepseek-r1:14b",
|
||||
server_address="192.168.1.100:5000")
|
||||
|
||||
agent = CoderAgent(model="deepseek-r1:14b",
|
||||
name="Marcus the code agent",
|
||||
prompt_path="prompts/coder_agent.txt",
|
||||
provider=server_provider)
|
||||
|
||||
while True:
|
||||
query = get_user_query()
|
||||
if query is None:
|
||||
break
|
||||
answer, reasoning = agent.answer(query, speech_module)
|
||||
pretty_print(answer, color="output")
|
||||
if args.speak:
|
||||
speech_module.speak(answer)
|
||||
|
||||
def handleInterrupt(signum, frame):
|
||||
sys.exit(0)
|
||||
|
||||
def main():
|
||||
signal.signal(signal.SIGINT, handler=handleInterrupt)
|
||||
conversation_loop()
|
||||
interaction = Interaction([agent], tts_enabled=args.speak)
|
||||
while interaction.is_active:
|
||||
interaction.get_user()
|
||||
interaction.think()
|
||||
interaction.show_answer()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
44
sources/interaction.py
Normal file
44
sources/interaction.py
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
from sources.text_to_speech import Speech
|
||||
from sources.utility import pretty_print
|
||||
|
||||
class Interaction:
|
||||
def __init__(self, agents, tts_enabled: bool = False):
|
||||
self.tts_enabled = tts_enabled
|
||||
self.agents = agents
|
||||
self.speech = Speech()
|
||||
self.is_active = True
|
||||
self.last_query = None
|
||||
self.last_answer = None
|
||||
|
||||
def is_active(self):
|
||||
return self.is_active
|
||||
|
||||
def read_stdin(self) -> str:
|
||||
buffer = ""
|
||||
|
||||
while buffer == "" or buffer.isascii() == False:
|
||||
try:
|
||||
buffer = input(f">>> ")
|
||||
except EOFError:
|
||||
return None
|
||||
if buffer == "exit":
|
||||
return None
|
||||
return buffer
|
||||
|
||||
def get_user(self):
|
||||
query = self.read_stdin()
|
||||
if query is None:
|
||||
self.is_active = False
|
||||
return
|
||||
self.last_query = query
|
||||
return query
|
||||
|
||||
def think(self):
|
||||
self.last_answer, _ = self.agents[0].answer(self.last_query, self.speech)
|
||||
|
||||
def show_answer(self):
|
||||
pretty_print(self.last_answer, color="output")
|
||||
if self.tts_enabled:
|
||||
self.speech.speak(self.last_answer)
|
||||
|
Loading…
x
Reference in New Issue
Block a user