Skip to content

Instantly share code, notes, and snippets.

@pavlovmilen
Created April 8, 2024 13:22
Show Gist options
  • Save pavlovmilen/ccccee6971c27e9cb6a7dfc51332a723 to your computer and use it in GitHub Desktop.
Save pavlovmilen/ccccee6971c27e9cb6a7dfc51332a723 to your computer and use it in GitHub Desktop.
Azure Open AI client code
//https://youropenaiinstance.openai.azure.com/
//c#
// Note: The Azure OpenAI client library for .NET is in preview.
// Install the .NET library via NuGet: dotnet add package Azure.AI.OpenAI --version 1.0.0-beta.5
using Azure;
using Azure.AI.OpenAI;
OpenAIClient client = new OpenAIClient(
new Uri("https://youropenaiinstance.openai.azure.com/"),
new AzureKeyCredential(Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY")));
Response<ChatCompletions> responseWithoutStream = await client.GetChatCompletionsAsync(
"gpt35turbo",
new ChatCompletionsOptions()
{
Messages =
{
new ChatMessage(ChatRole.System, @"You are an AI assistant that helps people find information."),
},
Temperature = (float)0.7,
MaxTokens = 800,
NucleusSamplingFactor = (float)0.95,
FrequencyPenalty = 0,
PresencePenalty = 0,
});
ChatCompletions response = responseWithoutStream.Value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment