forked from kimjammer/Neuro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompter.py
65 lines (55 loc) · 2.41 KB
/
prompter.py
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
import time
from constants import PATIENCE
class Prompter:
def __init__(self, signals, llms, modules=None):
self.signals = signals
self.llms = llms
if modules is None:
self.modules = {}
else:
self.modules = modules
self.system_ready = False
self.timeSinceLastMessage = 0.0
def prompt_now(self):
# Don't prompt AI if system isn't ready yet
if not self.signals.stt_ready or not self.signals.tts_ready:
return False
# Don't prompt AI when anyone is currently talking
if self.signals.human_speaking or self.signals.AI_thinking or self.signals.AI_speaking:
return False
# Prompt AI if human said something
if self.signals.new_message:
return True
# Prompt AI if there are unprocessed chat messages
if len(self.signals.recentTwitchMessages) > 0:
return True
# Prompt if some amount of seconds has passed without anyone talking
if self.timeSinceLastMessage > PATIENCE:
return True
def chooseLLM(self):
if "multimodal" in self.modules and self.modules["multimodal"].API.multimodal_now():
return self.llms["image"]
else:
return self.llms["text"]
def prompt_loop(self):
print("Prompter loop started")
while not self.signals.terminate:
# Set lastMessageTime to now if program is still starting
if self.signals.last_message_time == 0.0 or (not self.signals.stt_ready or not self.signals.tts_ready):
self.signals.last_message_time = time.time()
self.timeSinceLastMessage = 0.0
else:
if not self.system_ready:
print("SYSTEM READY")
self.system_ready = True
# Calculate and set time since last message
self.timeSinceLastMessage = time.time() - self.signals.last_message_time
self.signals.sio_queue.put(("patience_update", {"crr_time": self.timeSinceLastMessage, "total_time": PATIENCE}))
# Decide and prompt LLM
if self.prompt_now():
print("PROMPTING AI")
llmWrapper = self.chooseLLM()
llmWrapper.prompt()
self.signals.last_message_time = time.time()
# Sleep for 0.1 seconds before checking again.
time.sleep(0.1)