File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 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 ) ;
You can’t perform that action at this time.
0 commit comments