Merge pull request #13 from birbbit/hb/save_computer_msg

save computer message + misc fixes
pull/14/head
killian 11 months ago committed by GitHub
commit ec761b5686
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -140,7 +140,8 @@ async def websocket_communication(WS_URL):
print("Press the spacebar to start/stop recording. Press ESC to exit.") print("Press the spacebar to start/stop recording. Press ESC to exit.")
asyncio.create_task(message_sender(websocket)) asyncio.create_task(message_sender(websocket))
message_so_far = {"role": None, "type": None, "format": None, "content": None} initial_message = {"role": None, "type": None, "format": None, "content": None}
message_so_far = initial_message
while True: while True:
message = await websocket.recv() message = await websocket.recv()
@ -150,8 +151,12 @@ async def websocket_communication(WS_URL):
if type(message) == str: if type(message) == str:
message = json.loads(message) message = json.loads(message)
if message.get("end"):
print(f"Complete message from the server: {message_so_far}")
message_so_far = initial_message
if "content" in 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 if key != "content"):
message_so_far = message message_so_far = message
else: else:
message_so_far["content"] += message["content"] message_so_far["content"] += message["content"]

@ -153,7 +153,7 @@ async def listener():
messages = json.load(file) messages = json.load(file)
messages.append(message) messages.append(message)
with open(conversation_history_path, 'w') as file: with open(conversation_history_path, 'w') as file:
json.dump(messages, file) json.dump(messages, file, indent=4)
accumulated_text = "" accumulated_text = ""
@ -193,7 +193,7 @@ async def listener():
await from_user.put(temp_message) 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, indent=4)
print("New user message recieved. Breaking.") print("New user message recieved. Breaking.")
break break
@ -202,11 +202,14 @@ async def listener():
if not from_computer.empty(): if not from_computer.empty():
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, indent=4)
print("New computer message recieved. Breaking.") print("New computer message recieved. Breaking.")
break break
else:
with open(conversation_history_path, 'w') as file:
json.dump(interpreter.messages, file, indent=4)
async def stream_or_play_tts(sentence): async def stream_or_play_tts(sentence):

Loading…
Cancel
Save