ChatResponseExtensions.AddMessagesAsync Method

Definition

Converts the updates into ChatMessage instances and adds them to list.

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

Parameters

list
IList<ChatMessage>

The list to which the newly constructed messages should be added.

updates
IAsyncEnumerable<ChatResponseUpdate>

The ChatResponseUpdate instances to convert to messages and add to the list.

cancellationToken
CancellationToken

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

Returns

A Task representing the completion of the operation.

Exceptions

updates is null.

Remarks

As part of combining updates into a series of ChatMessage instances, tne method may use MessageId to determine message boundaries, as well as coalesce contiguous AIContent items where applicable, e.g. multiple TextContent instances in a row may be combined into a single TextContent.

Applies to