diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index a58b84c714..1daccff6ad 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -667,6 +667,18 @@ def handle_responses_streaming_event( return current_output, None + elif event_type == 'response.output_item.done': + # Delta Event: Output item complete + item = data.get('item') + output_index = data.get('output_index', len(current_output) - 1) + + new_output = list(current_output) + if item and 0 <= output_index < len(current_output): + new_output[output_index] = item + elif item: + new_output.append(item) + return new_output, {} + elif event_type.startswith('response.') and event_type.endswith('.done'): # Delta Events: response.content_part.done, response.text.done, etc. parts = event_type.split('.') @@ -711,12 +723,8 @@ def handle_responses_streaming_event( return new_output, {} return current_output, None - # 2. Skip Output Item done (handled specifically below) - if type_name == 'output_item': - pass - - # 3. Generic Field Done (text.done, audio.done) - elif type_name not in ['completed', 'failed']: + # 2. Generic Field Done (text.done, audio.done) + if type_name not in ['completed', 'failed']: output_index = data.get('output_index', len(current_output) - 1) if current_output and 0 <= output_index < len(current_output): key = ( @@ -760,18 +768,6 @@ def handle_responses_streaming_event( return current_output, None - elif event_type == 'response.output_item.done': - # Delta Event: Output item complete - item = data.get('item') - output_index = data.get('output_index', len(current_output) - 1) - - new_output = list(current_output) - if item and 0 <= output_index < len(current_output): - new_output[output_index] = item - elif item: - new_output.append(item) - return new_output, {} - elif event_type == 'response.completed': # State Machine Event: Completed response_data = data.get('response', {})