8th Architecture

pull/11/head
killian 11 months ago
parent 47b31fb5e1
commit 2a603581b5

@ -1 +1 @@
[{"role": "user", "type": "message", "content": "Yeah, it's explaining why you have to be a paramedic.\n"}, {"role": "user", "type": "message", "content": "\uc5b4\ub9b4\ub54c \uad1c\ucc2e\uc558\ub294\ub370 \uc544 \uadf8\ub798\uc11c \uc544\uce68\uc5d0 \uc9c4\uc9dc \uc548\uac00\uc9c0\uace0 \uc654\ub098\ubd10\uc694 \uc57c \ub098 \uc6ec\ub9cc\ud07c \ub9db\uc788\ub294\ub370\n"}, {"role": "user", "type": "message", "content": "Like, you'd have to go, like, out of houses.\n"}] [{"role": "user", "type": "message", "content": "Hi, please just immediately run print hello world, don't do anything else.\n"}, {"role": "user", "type": "message", "content": "Can you calculate something like 1,933 times 2,345? Again, please just do it immediately. Don't do anything else. Just please run the code. Don't send a message to me.\n"}]

@ -137,11 +137,15 @@ async def websocket_communication(WS_URL):
message_so_far = {"role": None, "type": None, "format": None, "content": None} message_so_far = {"role": None, "type": None, "format": None, "content": None}
async for message in websocket: while True:
message = await websocket.recv()
print(message) print("Got this message from the server:", type(message), message)
if "content" in message_so_far: if type(message) == str:
message = json.loads(message)
if "content" in message:
if any(message_so_far[key] != message[key] for key in message_so_far): if any(message_so_far[key] != message[key] for key in message_so_far):
message_so_far = message message_so_far = message
else: else:

@ -109,7 +109,7 @@ async def receive_messages(websocket: WebSocket):
async def send_messages(websocket: WebSocket): async def send_messages(websocket: WebSocket):
while True: while True:
message = await to_device.get() message = await to_device.get()
print(message) print("Sending to the device:", type(message), message)
await websocket.send_json(message) await websocket.send_json(message)
async def user_listener(): async def user_listener():
@ -117,6 +117,9 @@ async def user_listener():
while True: while True:
message = await from_user.get() message = await from_user.get()
if type(message) == str:
message = json.loads(message)
# Hold the audio in a buffer. If it's ready (we got end flag, stt it) # Hold the audio in a buffer. If it's ready (we got end flag, stt it)
if message["type"] == "audio": if message["type"] == "audio":
if "content" in message: if "content" in message:
@ -131,7 +134,7 @@ async def user_listener():
continue continue
# Ignore flags, we only needed them for audio ^ # Ignore flags, we only needed them for audio ^
if "content" not in message: if "content" not in message or message["content"] == None:
continue continue
# Custom stop message will halt us # Custom stop message will halt us
@ -147,10 +150,14 @@ async def user_listener():
accumulated_text = "" accumulated_text = ""
for chunk in interpreter.chat(messages, stream=True): for chunk in interpreter.chat(messages, stream=True, display=False):
print("Got chunk:", chunk)
# Send it to the user # Send it to the user
await to_device.put(chunk) await to_device.put(chunk)
# Yield to the event loop, so you actually send it out
await asyncio.sleep(0.01)
# Speak full sentences out loud # Speak full sentences out loud
if chunk["role"] == "assistant" and "content" in chunk: if chunk["role"] == "assistant" and "content" in chunk:
@ -167,8 +174,21 @@ async def user_listener():
# If we have a new message, save our progress and go back to the top # If we have a new message, save our progress and go back to the top
if not from_user.empty(): if not from_user.empty():
# Check if it's just an end flag. We ignore those.
temp_message = await from_user.get()
if temp_message == {'role': 'user', 'type': 'message', 'end': True}:
# Yup. False alarm.
continue
else:
# Whoops! Put that back
await from_user.put(temp_message)
with open(conversation_history_path, 'w') as file: with open(conversation_history_path, 'w') as file:
json.dump(interpreter.messages, file) json.dump(interpreter.messages, file)
print("New message recieved. Breaking.")
break break
async def stream_or_play_tts(sentence): async def stream_or_play_tts(sentence):

Loading…
Cancel
Save