Created
October 14, 2023 12:48
-
-
Save huanlin/7a563aa8535cbbf1527e066ef29947ca to your computer and use it in GitHub Desktop.
Azure OpenAI C# example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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