Skip to content

Commit e6ff531

Browse files
Algorithm5838github-actions[bot]
authored andcommitted
fix: skip reasoning preceded by text
1 parent ddf3f05 commit e6ff531

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

backend/open_webui/utils/middleware.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,6 +3700,10 @@ def set_last_text(out, text):
37003700
before_tag = item_text[: match.start()]
37013701
after_tag = item_text[match.end() :]
37023702

3703+
# Tag in prose text, skip it.
3704+
if before_tag.strip():
3705+
continue
3706+
37033707
# Keep only text before the tag in the message
37043708
set_last_text(output, before_tag)
37053709

@@ -4303,6 +4307,15 @@ async def queue_pending_delta_data(delta_data: dict, delta_type: str):
43034307
or delta.get('thinking')
43044308
)
43054309
reasoning_details = delta.get('reasoning_details')
4310+
4311+
# Native counterpart of `before_tag.strip()`: skip reasoning that
4312+
# arrives once the answer has begun.
4313+
if reasoning_content and output and output[-1].get('type') == 'message' and ''.join(
4314+
p.get('text', '') for p in output[-1].get('content', [])
4315+
).strip():
4316+
reasoning_content = ''
4317+
reasoning_details = None
4318+
43064319
if reasoning_content or reasoning_details:
43074320
reasoning_item = (
43084321
next(

0 commit comments

Comments
 (0)