diff --git a/backend/open_webui/utils/chat.py b/backend/open_webui/utils/chat.py index a769d5f1df..0b64a52165 100644 --- a/backend/open_webui/utils/chat.py +++ b/backend/open_webui/utils/chat.py @@ -269,24 +269,25 @@ async def generate_chat_completion( bypass_filter=True, bypass_system_prompt=bypass_system_prompt, ) + # Upstream errors come back as a response object. + if not isinstance(response, StreamingResponse): + return response return StreamingResponse( stream_wrapper(response.body_iterator), media_type='text/event-stream', background=response.background, ) else: - return { - **( - await generate_chat_completion( - request, - form_data, - user, - bypass_filter=True, - bypass_system_prompt=bypass_system_prompt, - ) - ), - 'selected_model_id': selected_model_id, - } + response = await generate_chat_completion( + request, + form_data, + user, + bypass_filter=True, + bypass_system_prompt=bypass_system_prompt, + ) + if not isinstance(response, dict): + return response + return {**response, 'selected_model_id': selected_model_id} if model.get('pipe'): # Below does not require bypass_filter because this is the only route the uses this function and it is already bypassing the filter