Skip to content

Commit 86ffde3

Browse files
committed
fix: prevent answer split from late reasoning
1 parent 9f2309e commit 86ffde3

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

backend/open_webui/utils/middleware.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4322,12 +4322,14 @@ async def queue_pending_delta_data(delta_data: dict, delta_type: str):
43224322
reasoning_details = None
43234323

43244324
if reasoning_content or reasoning_details:
4325+
# Merge late reasoning into the pre-message block so the answer isn't split.
4326+
answer_started = any(item.get('type') == 'message' for item in output)
43254327
reasoning_item = (
43264328
next(
43274329
(item for item in reversed(output) if item.get('type') == 'reasoning'),
43284330
None,
43294331
)
4330-
if reasoning_details and not reasoning_content
4332+
if (reasoning_details and not reasoning_content) or answer_started
43314333
else None
43324334
)
43334335

@@ -4344,7 +4346,13 @@ async def queue_pending_delta_data(delta_data: dict, delta_type: str):
43444346
'summary': None,
43454347
'started_at': time.time(),
43464348
}
4347-
output.append(reasoning_item)
4349+
if answer_started:
4350+
insert_at = next(
4351+
i for i, x in enumerate(output) if x.get('type') == 'message'
4352+
)
4353+
output.insert(insert_at, reasoning_item)
4354+
else:
4355+
output.append(reasoning_item)
43484356
else:
43494357
reasoning_item = output[-1]
43504358

0 commit comments

Comments
 (0)