TextUIMessageStream
Namespace: Vercel.AI.AspNetCore
public static class TextUIMessageStreamTurns plain text into the UI message chunks a text-only client expects.
Inheritance: object
Methods
Section titled “Methods”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
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>
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product