[GH-ISSUE #23922] fix: Missing delta.role and non-unique chunk IDs in Ollama-to-OpenAI SSE conversion #35638

Closed
opened 2026-04-25 09:48:06 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @pvyswiss on GitHub (Apr 21, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/23922

Bug Description

API clients fail to correlate SSE chunks or initialize the response correctly. Some SDKs silently drop chunks or fail to render content.

Related to: #23917 (Bug 3)

Root Cause (Two Issues)

3a: Missing delta.role: "assistant" on first chunk

The OpenAI SSE spec requires the first chunk to contain delta.role: "assistant". The Ollama-to-OpenAI conversion never emits role. OpenAI-compatible SDKs expect this field.

3b: Unique UUID per SSE chunk

openai_chat_message_template() generates a new uuid4() per chunk. The OpenAI spec requires all chunks in a completion to share the same id. SDKs use this for chunk correlation.

Fix

async def convert_streaming_response_ollama_to_openai(ollama_streaming_response):
    first_chunk = True
    completion_id = f'chatcmpl-{uuid4()}'

    async for data in ollama_streaming_response.body_iterator:
        data['id'] = completion_id  # Same ID for all chunks
        if first_chunk:
            data['choices'][0]['delta']['role'] = 'assistant'
            first_chunk = False

Impact

  • Web UI: None (browser path doesn't use chunk id or delta.role)
  • API clients: Proper chunk correlation and response initialization

File

backend/open_webui/utils/response.py

Originally created by @pvyswiss on GitHub (Apr 21, 2026). Original GitHub issue: https://github.com/open-webui/open-webui/issues/23922 ## Bug Description API clients fail to correlate SSE chunks or initialize the response correctly. Some SDKs silently drop chunks or fail to render content. Related to: #23917 (Bug 3) ## Root Cause (Two Issues) ### 3a: Missing `delta.role: "assistant"` on first chunk The OpenAI SSE spec requires the first chunk to contain `delta.role: "assistant"`. The Ollama-to-OpenAI conversion never emits `role`. OpenAI-compatible SDKs expect this field. ### 3b: Unique UUID per SSE chunk `openai_chat_message_template()` generates a new `uuid4()` per chunk. The OpenAI spec requires all chunks in a completion to share the same `id`. SDKs use this for chunk correlation. ## Fix ```python async def convert_streaming_response_ollama_to_openai(ollama_streaming_response): first_chunk = True completion_id = f'chatcmpl-{uuid4()}' async for data in ollama_streaming_response.body_iterator: data['id'] = completion_id # Same ID for all chunks if first_chunk: data['choices'][0]['delta']['role'] = 'assistant' first_chunk = False ``` ## Impact - **Web UI**: None (browser path doesn't use chunk `id` or `delta.role`) - **API clients**: Proper chunk correlation and response initialization ## File `backend/open_webui/utils/response.py`
Author
Owner

@tjbck commented on GitHub (Apr 24, 2026):

Addressed in dev.

<!-- gh-comment-id:4311448826 --> @tjbck commented on GitHub (Apr 24, 2026): Addressed in dev.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#35638