From 2d5b82df8c9f48e1211dae3394e6eb2f5694cb6c Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 26 May 2025 22:22:37 +0400 Subject: [PATCH] enh: include sources field in non-streaming response --- backend/open_webui/utils/middleware.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 39b2a4c19..86e1102c5 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -1217,8 +1217,34 @@ async def process_chat_response( await background_tasks_handler() + if events and isinstance(events, list) and isinstance(response, dict): + extra_response = {} + for event in events: + if isinstance(event, dict): + extra_response.update(event) + else: + extra_response[event] = True + + response = { + **extra_response, + **response, + } + return response else: + if events and isinstance(events, list) and isinstance(response, dict): + extra_response = {} + for event in events: + if isinstance(event, dict): + extra_response.update(event) + else: + extra_response[event] = True + + response = { + **extra_response, + **response, + } + return response # Non standard response