openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.6.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

examples/Responses/Example02_SimpleResponseStreamingAsync.cs

34lines · modecode

1using NUnit.Framework;
2using OpenAI.Responses;
3using System;
4using System.ClientModel;
5using System.Threading.Tasks;
6
7namespace OpenAI.Examples;
8
9// This example uses experimental APIs which are subject to change. To use experimental APIs,
10// please acknowledge their experimental status by suppressing the corresponding warning.
11
12#pragma warning disable OPENAI001
13
14public partial class ResponseExamples
15{
16 [Test]
17 public async Task Example02_SimpleResponseStreamingAsync()
18 {
19 OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
20
21 AsyncCollectionResult<StreamingResponseUpdate> responseUpdates = client.CreateResponseStreamingAsync("Say 'this is a test.'");
22
23 Console.Write($"[ASSISTANT]: ");
24 await foreach (StreamingResponseUpdate update in responseUpdates)
25 {
26 if (update is StreamingResponseOutputTextDeltaUpdate outputTextUpdate)
27 {
28 Console.Write(outputTextUpdate.Delta);
29 }
30 }
31 }
32}
33
34#pragma warning restore OPENAI001