-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdouble_trouble.py
More file actions
76 lines (63 loc) · 2.53 KB
/
Copy pathdouble_trouble.py
File metadata and controls
76 lines (63 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from RealtimeTTS import TextToAudioStream, CoquiEngine, SystemEngine
from langchain_ollama import ChatOllama
import time
def install(voice=None):
engine = CoquiEngine(voice=voice,pretrained=True)
return engine
def install_system(voice):
engine = SystemEngine(voice)
return engine
def system_prompt(prompt, user_message):
return [
("system", prompt),
("user", user_message)
]
if __name__ == '__main__':
# Initialize the TTS engine and LLMs
print("Initializing")
engine = install()
enginetwo = install(voice="bane.wav")
print("created engine")
stream = TextToAudioStream(engine)
second = TextToAudioStream(enginetwo)
llm1 = ChatOllama(model="bob:latest", base_url="http://localhost:11434", num_predict=-2, disable_streaming=True)
llm2 = ChatOllama(model="lisa:latest", base_url="http://localhost:11434", num_predict=-2, disable_streaming=True)
# Initialize chat memory and system prompt
chat_memory = []
initial_prompt = input("Prompt bot one:")
initial_prompttwo = input("Prompt bot two")
print("We here")
user_input = input("User:")
while True:
try:
# LLM1 interaction
messages = system_prompt(initial_prompt, user_input)
llm1_response = llm1.invoke(messages)
response1 = llm1_response.content
chat_memory.extend((("user", user_input), ("Assistant1", response1)))
# Play LLM1's response
stream.feed(response1)
stream.play_async(output_wavfile="newtests.wav")
print(f"LLM1: {response1}")
while stream.is_playing():
time.sleep(0.1)
#engine.set_voice("bane.wav")
# Pass LLM1's response to LLM2
messages = system_prompt(initial_prompt, response1)
llm2_response = llm2.invoke(messages)
response2 = llm2_response.content
chat_memory.append(("Assistant2", response2))
# Play LLM2's response
second.feed(response2)
second.play_async(output_wavfile="newtests2.wav")
print(f"LLM2: {response2}")
while second.is_playing():
time.sleep(0.1)
# Update user_input with LLM2's response for the next loop iteration
user_input = response2
# Optional: Add a stopping condition if the conversation should not be infinite
if "stop" in response2.lower():
break
except KeyboardInterrupt:
engine.shutdown()
break