openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

examples/Chat/Example02_SimpleChatStreaming.cs

30lines · modecode

1using NUnit.Framework;
2using OpenAI.Chat;
3using System;
4using System.ClientModel;
5
6namespace OpenAI.Examples;
7
8public partial class ChatExamples
9{
10 [Test]
11 public void Example02_SimpleChatStreaming()
12 {
13 ChatClient client = new("gpt-4o", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
14
15 ResultCollection<StreamingChatCompletionUpdate> chatUpdates
16 = client.CompleteChatStreaming(
17 [
18 new UserChatMessage("Say 'this is a test.'"),
19 ]);
20
21 Console.WriteLine($"[ASSISTANT]:");
22 foreach (StreamingChatCompletionUpdate chatUpdate in chatUpdates)
23 {
24 foreach (ChatMessageContentPart contentPart in chatUpdate.ContentUpdate)
25 {
26 Console.Write(contentPart.Text);
27 }
28 }
29 }
30}
31