From 9c62eb02bdb733a402a23775a4f7bec0a7b6c85b Mon Sep 17 00:00:00 2001 From: Abby Hartman Date: Fri, 12 Apr 2024 15:57:59 -0700 Subject: [PATCH] Fix issue with keyerror in list comprehension --- app.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 2679ff2741..c04c28b768 100644 --- a/app.py +++ b/app.py @@ -820,7 +820,12 @@ async def promptflow_request(request): async def send_chat_request(request): - filtered_messages = [message for message in request['messages'] if message['role'] != 'tool'] + filtered_messages = [] + messages = request.get("messages", []) + for message in messages: + if message.get("role") != 'tool': + filtered_messages.append(message) + request['messages'] = filtered_messages model_args = prepare_model_args(request)