Last active
April 8, 2024 14:41
-
-
Save pavlovmilen/5de261c91b38ebf771b77ca2a9a5b8c1 to your computer and use it in GitHub Desktop.
Chat completion api usage
This file contains 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
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