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)