From 7e8b6df95172861ca13f757d668e21461ab9f08b Mon Sep 17 00:00:00 2001 From: Arun Chandrasekhar <14188700+achandmsft@users.noreply.github.com> Date: Thu, 26 Jun 2025 11:25:13 -0700 Subject: [PATCH] Create simpleprompt.cs Example on tying openai-dotnet docs to openai.com docs folder structure --- docs/guides/text/chat/simpleprompt.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 docs/guides/text/chat/simpleprompt.cs diff --git a/docs/guides/text/chat/simpleprompt.cs b/docs/guides/text/chat/simpleprompt.cs new file mode 100644 index 00000000..b98b8e1e --- /dev/null +++ b/docs/guides/text/chat/simpleprompt.cs @@ -0,0 +1,12 @@ +// Generate text from a simple prompt using Chat Completions API (https://platform.openai.com/docs/guides/text?api-mode=chat) +// This file can be run as an app using .NET 10 Preview 4 or later using the following steps +// 1. Set OPENAI_KEY environment variable to your OpenAI API key, never hardcode it. +// 2. Run this command: type chat_simpleprompt.cs +// 3. Run this commnd: dotnet run chat_simpleprompt.cs +#:package OpenAI@2.* +#:property PublishAot=false +using OpenAI.Chat; +string key = Environment.GetEnvironmentVariable("OPENAI_KEY")!; +ChatClient client = new (model: "gpt-4.1", apiKey: apiKey); +ChatCompletion acompletion = client.CompleteChat("list all noble gases"); +Console.WriteLine(acompletion.Content[0].Text);