Share via


ChatResponseExtensions.ToChatResponseAsync Method

Definition

Combines ChatResponseUpdate instances into a single ChatResponse.

public static System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse> ToChatResponseAsync(this System.Collections.Generic.IAsyncEnumerable<Microsoft.Extensions.AI.ChatResponseUpdate> updates, System.Threading.CancellationToken cancellationToken = default);
static member ToChatResponseAsync : System.Collections.Generic.IAsyncEnumerable<Microsoft.Extensions.AI.ChatResponseUpdate> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse>
<Extension()>
Public Function ToChatResponseAsync (updates As IAsyncEnumerable(Of ChatResponseUpdate), Optional cancellationToken As CancellationToken = Nothing) As Task(Of ChatResponse)

Parameters

updates
IAsyncEnumerable<ChatResponseUpdate>

The updates to be combined.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The combined ChatResponse.

Exceptions

updates is null.

Remarks

As part of combining updates into a single ChatResponse, the method will attempt to reconstruct ChatMessage instances. This includes using MessageId to determine message boundaries, as well as coalescing contiguous AIContent items where applicable, e.g. multiple TextContent instances in a row may be combined into a single TextContent.

Applies to