Skip to content

Instantly share code, notes, and snippets.

@pavlovmilen
Last active April 8, 2024 14:41
Show Gist options
  • Save pavlovmilen/5de261c91b38ebf771b77ca2a9a5b8c1 to your computer and use it in GitHub Desktop.
Save pavlovmilen/5de261c91b38ebf771b77ca2a9a5b8c1 to your computer and use it in GitHub Desktop.
Chat completion api usage
var url = _configuration.GetValue<string>("AzureOpenAiApi:Endpoint");
var key = _configuration.GetValue<string>("AzureOpenAiApi:SubscriptionKey");
var openAIClient = new OpenAIClient(new Uri(url), new AzureKeyCredential(key));
Response<ChatCompletions> responseWithoutStream =
await openAIClient.GetChatCompletionsAsync(
new ChatCompletionsOptions()
{
Messages =
{
new ChatRequestUserMessage($"Given this context {context} my question is {myQuestion}" ),
},
Temperature = _configuration.GetValue<float>("AzureOpenAiApi:Temperature"),
MaxTokens = 1000,
NucleusSamplingFactor = (float)0.95,
FrequencyPenalty = 0,
PresencePenalty = 0,
DeploymentName = _configuration.GetValue<string>("gpt35turbo"),
}
);
var result = responseWithoutStream.Value.Choices[0].Message.Content;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment