Skip to content

Chat Client Five Random Words Streaming

This example assumes using AI21; is in scope and apiKey contains your AI21 API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
using var client = GetAuthorizedClient();

IChatClient chatClient = client;
var updates = chatClient.GetStreamingResponseAsync(
    [
        new ChatMessage(ChatRole.User, "Generate 5 random words.")
    ],
    new ChatOptions
    {
        ModelId = "jamba-large",
    });

var deltas = new List<string>();
await foreach (var update in updates)
{
    if (!string.IsNullOrWhiteSpace(update.Text))
    {
        deltas.Add(update.Text);
    }
}