parent
3f92df120b
commit
9359f1dd91
@ -1,28 +1,38 @@
|
|||||||
while True:
|
import redis
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
message = None
|
# Set up Redis connection
|
||||||
while message is None:
|
r = redis.Redis(host='localhost', port=6379, db=0)
|
||||||
message = get_from_queue('to_main')
|
|
||||||
|
|
||||||
if message == user_start_message:
|
def main(interpreter):
|
||||||
continue
|
|
||||||
|
|
||||||
messages = get_conversation_history()
|
while True:
|
||||||
messages.append(message)
|
|
||||||
save_conversation_history(message)
|
|
||||||
|
|
||||||
sentence = ""
|
|
||||||
|
|
||||||
for chunk in interpreter.chat(messages):
|
# Check 10x a second for new messages
|
||||||
|
message = None
|
||||||
if queue_length() > 0:
|
while message is None:
|
||||||
save_conversation_history(interpreter.messages)
|
message = r.lpop('to_core')
|
||||||
break
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
# Custom stop message will halt us
|
||||||
|
if message.get("content") and message.get("content").lower().strip(".,!") == "stop":
|
||||||
|
continue
|
||||||
|
|
||||||
send_to_io(chunk)
|
# Load, append, and save conversation history
|
||||||
|
with open("conversations/user.json", "r") as file:
|
||||||
|
messages = json.load(file)
|
||||||
|
messages.append(message)
|
||||||
|
with open("conversations/user.json", "w") as file:
|
||||||
|
json.dump(messages, file)
|
||||||
|
|
||||||
|
for chunk in interpreter.chat(messages):
|
||||||
|
|
||||||
sentence += chunk
|
# Send it to the interface
|
||||||
if is_full_sentence(sentence):
|
r.rpush('to_interface', chunk)
|
||||||
audio = tts(sentence)
|
|
||||||
sentence = ""
|
# If we have a new message, save our progress and go back to the top
|
||||||
send_to_io(audio)
|
if r.llen('to_main') > 0:
|
||||||
|
with open("conversations/user.json", "w") as file:
|
||||||
|
json.dump(interpreter.messages, file)
|
||||||
|
break
|
||||||
|
Loading…
Reference in new issue