diff --git a/backend/open_webui/socket/main.py b/backend/open_webui/socket/main.py index c3678f592d..69c24507b7 100644 --- a/backend/open_webui/socket/main.py +++ b/backend/open_webui/socket/main.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +import copy import logging import random import sys @@ -1006,6 +1007,9 @@ async def _make_channel_emitter(request_info): if not content and not output and not done: return + if isinstance(output, list): + state['output'] = copy.deepcopy(output) + now = time.time() if done or (now - state['last_emit_at']) >= THROTTLE_INTERVAL: state['last_emit_at'] = now diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 8ab00a9185..f7aec88e5a 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -5447,6 +5447,8 @@ async def streaming_chat_response_handler(response, ctx): } ] + pre_tag_item_id = output[-1].get('id') + if DETECT_REASONING_TAGS: output, _ = tag_output_handler( 'reasoning', @@ -5488,6 +5490,15 @@ async def streaming_chat_response_handler(response, ctx): } delta_type = delta_event_type + # the raw chunk still carries the tag text: resend the cleaned output instead + if target_item.get('id') != pre_tag_item_id: + await flush_pending_delta_data() + await event_emitter( + {'type': 'chat:completion', 'data': {'output': full_output()}} + ) + await save_current_response_stream() + data = None + if delta and data: await queue_pending_delta_data(data, delta_type) elif data: diff --git a/src/lib/components/chat/Messages/structuredOutput.ts b/src/lib/components/chat/Messages/structuredOutput.ts index 55ef655a2b..cede49a3f0 100644 --- a/src/lib/components/chat/Messages/structuredOutput.ts +++ b/src/lib/components/chat/Messages/structuredOutput.ts @@ -626,6 +626,11 @@ export function applyResponseStreamEvent( return nextOutput; } + if (item.type === 'open_webui:code_interpreter') { + item.code = appendDelta(item.code ?? '', event.delta); + return nextOutput; + } + const key = deltaType === 'output_text' || deltaType === 'reasoning_text' ? 'text' : deltaType; item.content = [...(item.content ?? [])]; const part = ensurePart(item.content, event.content_index ?? 0);