Skip to content

TextUIMessageStream

Namespace: Vercel.AI.AspNetCore

public static class TextUIMessageStream

Turns plain text into the UI message chunks a text-only client expects.

Inheritance: object

View source

ProcessAsync(IAsyncEnumerable<byte[]>, Func<string, Task>, CancellationToken)

Section titled “ProcessAsync(IAsyncEnumerable<byte[]>, Func<string, Task>, CancellationToken)”
public static Task ProcessAsync(IAsyncEnumerable<byte[]> chunks, Func<string, Task> onTextPart, CancellationToken cancellationToken = default)

Decodes UTF-8 chunks and passes each decoded piece to <code class=“paramref”>onTextPart</code>.

Parameters

Name Type Description
chunks IAsyncEnumerable<byte[]> Encoded text pieces. An empty sequence does not call <code class=“paramref”>onTextPart</code>.
onTextPart Func<string, Task> Receives one decoded piece.
cancellationToken CancellationToken Cancels reading <code class=“paramref”>chunks</code>.

Returns: Task

View source

TransformAsync(IAsyncEnumerable<string>, CancellationToken)

Section titled “TransformAsync(IAsyncEnumerable<string>, CancellationToken)”
public static IAsyncEnumerable<JsonObject> TransformAsync(IAsyncEnumerable<string> text, CancellationToken cancellationToken = default)

Wraps <code class=“paramref”>text</code> in start, one text block with id text-1, and finish chunks. An empty source still emits the surrounding chunks and no text delta.

Parameters

Name Type Description
text IAsyncEnumerable<string> Text pieces, in order.
cancellationToken CancellationToken Cancels reading <code class=“paramref”>text</code>.

Returns: IAsyncEnumerable<JsonObject>

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product