From 8081ac299fbd555ae64934ab5ae8252e938aff2b Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sat, 26 Sep 2026 05:18:35 +0200 Subject: [PATCH] fix: missing space in reasoning model answers right after the thinking block (#31438) With reasoning models, when the first part of the answer arrived together with the end of the thinking block and ended with a space, that space went missing, so "The answer is 4." was shown and saved as "The answeris 4.". That space is now kept. Fixes #31435 --- backend/open_webui/utils/middleware.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 5407085707..f629b73dd2 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -4682,14 +4682,14 @@ async def streaming_chat_response_handler(response, ctx): # Strip start and end tags from content start_tag_pattern = _start_tag_pattern(start_tag) - block_content = re.sub(start_tag_pattern, '', block_content).strip() + block_content = re.sub(start_tag_pattern, '', block_content) end_tag_pattern = rf'{re.escape(end_tag)}' end_tag_regex = re.compile(end_tag_pattern, re.DOTALL) split_content = end_tag_regex.split(block_content, maxsplit=1) block_content = split_content[0].strip() if split_content else '' - leftover_content = split_content[1].strip() if len(split_content) > 1 else '' + leftover_content = split_content[1].lstrip() if len(split_content) > 1 else '' if block_content: # Update the item with final content