From 80ba6a7be9868ef99734119915cb10c778ab2028 Mon Sep 17 00:00:00 2001 From: pmuralikrishna111 Date: Wed, 22 Jan 2025 16:54:01 +0400 Subject: [PATCH 1/2] Update rtmt.py - pop gives the error when there are two message in the queue and there will be index out of range index out of the range. consider two message are in the queue and poping both like total size is 2 pop(1) - it will remove the first element and size becomes 1 pop(2) - it will try to remove the 2nd element but size is 1 and it will be index out of bounds --- app/backend/rtmt.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/backend/rtmt.py b/app/backend/rtmt.py index 4bdc20df..5304d875 100644 --- a/app/backend/rtmt.py +++ b/app/backend/rtmt.py @@ -146,9 +146,12 @@ async def _process_message_to_client(self, msg: str, client_ws: web.WebSocketRes }) if "response" in message: replace = False - for i, output in enumerate(reversed(message["response"]["output"])): + # Iterate in reverse while calculating the correct index + for reverse_index, output in enumerate(reversed(message["response"]["output"])): if output["type"] == "function_call": - message["response"]["output"].pop(i) + original_index = output_len - 1 - reverse_index # Map reversed index to the original + print("Len of message[response][output]:", output_len, ", output:", message["response"]["output"]) + message["response"]["output"].pop(original_index) replace = True if replace: updated_message = json.dumps(message) From e85ce760d57b2a0670faf87190b871832fe0cafc Mon Sep 17 00:00:00 2001 From: pmuralikrishna111 Date: Tue, 20 May 2025 21:53:27 +0400 Subject: [PATCH 2/2] Update rtmt.py - output_len variable declaration missed to add output_len variable declaration. --- app/backend/rtmt.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/backend/rtmt.py b/app/backend/rtmt.py index 5304d875..f9f7a7bc 100644 --- a/app/backend/rtmt.py +++ b/app/backend/rtmt.py @@ -146,6 +146,9 @@ async def _process_message_to_client(self, msg: str, client_ws: web.WebSocketRes }) if "response" in message: replace = False + # Get the original list length + output_len = len(message["response"]["output"]) + # Iterate in reverse while calculating the correct index for reverse_index, output in enumerate(reversed(message["response"]["output"])): if output["type"] == "function_call":