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/Example01_SimpleChat.cs

22lines · modecode

1using NUnit.Framework;
2using OpenAI.Chat;
3using System;
4
5namespace OpenAI.Examples;
6
7public 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