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
This commit is contained in:
Classic298 2026-09-26 05:18:35 +02:00 • committed by GitHub
parent 9d6b17ffbc
commit 8081ac299f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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