From 3b7c07b4d8c42779b8144f0fb1fb4b78c87fa9af Mon Sep 17 00:00:00 2001 From: silentoplayz Date: Mon, 28 Sep 2026 06:50:28 -0400 Subject: [PATCH] fix: stop reading reasoning tags in the answer once the provider sends reasoning separately --- backend/open_webui/utils/middleware.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 6a3e4b6f5b..3b7d50a999 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -4910,6 +4910,8 @@ async def streaming_chat_response_handler(response, ctx): joined_content = '' joined_part_count = 0 + streamed_reasoning_content = False + async def save_current_response_stream(stream_output: list | None = None): nonlocal joined_content nonlocal joined_part_count @@ -5429,6 +5431,8 @@ async def streaming_chat_response_handler(response, ctx): ) if reasoning_content and not isinstance(reasoning_content, str): reasoning_content = f'{reasoning_content}' + if reasoning_content: + streamed_reasoning_content = True reasoning_details = get_reasoning_details(delta) reasoning_detail_items = ( [item for item in reasoning_details if isinstance(item, dict)] @@ -5648,11 +5652,12 @@ async def streaming_chat_response_handler(response, ctx): tag_output = None if DETECT_REASONING_TAGS: - tag_output, _ = tag_output_handler( - 'reasoning', - reasoning_tags, - output, - ) + if not streamed_reasoning_content: + tag_output, _ = tag_output_handler( + 'reasoning', + reasoning_tags, + output, + ) solution_output, _ = tag_output_handler( 'solution',