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