-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchat.py
56 lines (48 loc) · 1.4 KB
/
chat.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
import sys
import logging
from prompts import Prompt
import speech_recognition as sr
from core import listen_to_me, brain, tell_to_me_use_azure, MAGIC_WORD_TO_END_CHAT
R = sr.Recognizer()
M = sr.Microphone()
conversation = []
# klug has context with brain
def klug(context, keep=False, talktome=False):
result = brain(context)
logging.info("BOT: {}".format(result))
if talktome:
tell_to_me_use_azure(result)
if keep:
context.append({
"role": "assistant",
"content": result})
context = context[-10:]
while True:
res = listen_to_me(R,M)
if res:
if MAGIC_WORD_TO_END_CHAT in res:
logging.info("Bot: Ended The Converstion")
sys.exit()
context.append({
"role": "user",
"content": res
})
break
else:
logging.info("I didn't hear what you were saying")
return klug(context, True, True)
return result
if sys.argv[1] == "interview":
conversation.append(Prompt.interview.value)
if sys.argv[1] == "speaker":
conversation.append(Prompt.english_speaker.value)
speak = False
if speak:
first = listen_to_me(R, M)
else:
first = "Hi"
conversation.append({
"role": "user",
"content": first
})
klug(conversation, keep=True, talktome=True)