openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
docs/guides/text/chat/chat_simpleprompt.cs
11lines · modecode
| 1 | // SAMPLE: Generate text from a simple prompt |
| 2 | // GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start |
| 3 | #:package OpenAI@2.* |
| 4 | #:property PublishAot=false |
| 5 | |
| 6 | using OpenAI.Chat; |
| 7 | |
| 8 | string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!; |
| 9 | ChatClient client = new("gpt-4.1", key); |
| 10 | ChatCompletion acompletion = client.CompleteChat("Write a one-sentence bedtime story about a unicorn."); |
| 11 | Console.WriteLine(acompletion.Content[0].Text); |