Skip to content

ChatResponseExtensions.ToChatResponse; No messageId present #359

@awaescher

Description

@awaescher

Discussed in #299

Originally posted by flintlouis August 14, 2025
Hi,
When using the OllamaApiClient, after getting the IAsyncEnumerable<ChatResponseUpdate> responseStream from GetStreamingResponseAsync(), I use the ChatResponseExtensions.ToChatResponse() from Micrsoft.Extensions.AI to squash all the seperate response chunks into a ChatResponse with a list of response messages. This extension uses the MessageId to distuingish which response chunks belong to which message and seperates it in this way.
But with the ChatResponseStream there are no message ID's implemented so this extension method just adds all AIContent into 1 message, even if it has a different role.

I was wondering, is it an idea to add messageId's to the ollama Message?

Example:
Before:
responseChunks =
[
{ role: assistant, content: [text] },
{ role: assistant, content: [tool_call] },
{ role: tool, content: [tool_response] },
{ role: assistant, content: [text] }
]
After:
response.Messages =
[
{ role: assistant, content: [text, tool_call, tool_response, text] }
]

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions