Skip to content

Create simpleprompt.cs #488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/guides/text/chat/simpleprompt.cs
Original file line number Diff line number Diff line change
@@ -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.*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#:package OpenAI@2.*
#:package OpenAI@2.*

#:property PublishAot=false
using OpenAI.Chat;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using OpenAI.Chat;
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Console.WriteLine(acompletion.Content[0].Text);
Console.WriteLine(acompletion.Content[0].Text);