openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
examples/Chat/Example01_SimpleChatAsync.cs
23lines · modecode
| 1 | using NUnit.Framework; |
| 2 | using OpenAI.Chat; |
| 3 | using System; |
| 4 | using System.Threading.Tasks; |
| 5 | |
| 6 | namespace OpenAI.Examples; |
| 7 | |
| 8 | public partial class ChatExamples |
| 9 | { |
| 10 | [Test] |
| 11 | public async Task Example01_SimpleChatAsync() |
| 12 | { |
| 13 | ChatClient client = new("gpt-4o", Environment.GetEnvironmentVariable("OPENAI_API_KEY")); |
| 14 | |
| 15 | ChatCompletion chatCompletion = await client.CompleteChatAsync( |
| 16 | [ |
| 17 | new UserChatMessage("Say 'this is a test.'"), |
| 18 | ]); |
| 19 | |
| 20 | Console.WriteLine($"[ASSISTANT]:"); |
| 21 | Console.WriteLine($"{chatCompletion.Content[0].Text}"); |
| 22 | } |
| 23 | } |
| 24 | |