diff --git a/OS/01/device.py b/OS/01/device.py index 8d675e1..d51444a 100644 --- a/OS/01/device.py +++ b/OS/01/device.py @@ -140,7 +140,8 @@ async def websocket_communication(WS_URL): print("Press the spacebar to start/stop recording. Press ESC to exit.") 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: message = await websocket.recv() @@ -150,8 +151,12 @@ async def websocket_communication(WS_URL): if type(message) == str: 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 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 else: message_so_far["content"] += message["content"] diff --git a/OS/01/server.py b/OS/01/server.py index eaeae28..f24bdef 100644 --- a/OS/01/server.py +++ b/OS/01/server.py @@ -153,7 +153,7 @@ async def listener(): messages = json.load(file) messages.append(message) with open(conversation_history_path, 'w') as file: - json.dump(messages, file) + json.dump(messages, file, indent=4) accumulated_text = "" @@ -193,7 +193,7 @@ async def listener(): await from_user.put(temp_message) 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.") break @@ -202,11 +202,14 @@ async def listener(): if not from_computer.empty(): 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.") break - + else: + with open(conversation_history_path, 'w') as file: + json.dump(interpreter.messages, file, indent=4) + async def stream_or_play_tts(sentence):