Skip to content

Commit 7e8b6df

Browse files
authored
Create simpleprompt.cs
Example on tying openai-dotnet docs to openai.com docs folder structure
1 parent 83d6bef commit 7e8b6df

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Generate text from a simple prompt using Chat Completions API (https://platform.openai.com/docs/guides/text?api-mode=chat)
2+
// This file can be run as an app using .NET 10 Preview 4 or later using the following steps
3+
// 1. Set OPENAI_KEY environment variable to your OpenAI API key, never hardcode it.
4+
// 2. Run this command: type chat_simpleprompt.cs
5+
// 3. Run this commnd: dotnet run chat_simpleprompt.cs
6+
#:package OpenAI@2.*
7+
#:property PublishAot=false
8+
using OpenAI.Chat;
9+
string key = Environment.GetEnvironmentVariable("OPENAI_KEY")!;
10+
ChatClient client = new (model: "gpt-4.1", apiKey: apiKey);
11+
ChatCompletion acompletion = client.CompleteChat("list all noble gases");
12+
Console.WriteLine(acompletion.Content[0].Text);

0 commit comments

Comments
 (0)