Skip to content

Instantly share code, notes, and snippets.

@huanlin
Created October 14, 2023 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huanlin/7a563aa8535cbbf1527e066ef29947ca to your computer and use it in GitHub Desktop.
Save huanlin/7a563aa8535cbbf1527e066ef29947ca to your computer and use it in GitHub Desktop.
Azure OpenAI C# example
using Azure;
using Azure.AI.OpenAI;
var key = "0bc0xxxxxxxxxxxxxxxx7971";
var endpoint = "https://my-demo-ai-app.openai.azure.com/";
var deployment = "turbo-michael-35";
Console.Write("Ask me anything: ");
var prompt = Console.ReadLine();
OpenAIClient aiClient = new(new Uri(endpoint), new AzureKeyCredential(key));
ChatCompletionsOptions chatOptions = new()
{
Messages =
{
new ChatMessage(ChatRole.System, "Please answer me with both Traditional Chinese and English."),
new ChatMessage(ChatRole.User, prompt)
}
};
ChatCompletions response = aiClient.GetChatCompletions(deployment, chatOptions);
Console.WriteLine("AI assistant replied: ");
Console.WriteLine(response.Choices[0].Message.Content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment