Last active
September 21, 2024 17:41
-
-
Save pavlovmilen/56a46cd5e7b0293a24c733d3d8374dca to your computer and use it in GitHub Desktop.
Chat client setup
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
// chat client setup code | |
var url = _configuration.GetValue<string>("AzureOpenAiApi:Endpoint"); | |
var key = _configuration.GetValue<string>("AzureOpenAiApi:SubscriptionKey"); | |
var openAIClient = new AzureOpenAIClient(new Uri(url), new AzureKeyCredential(key)); | |
var chatClient = openAIClient.GetChatClient(_configuration.GetValue<string>("AzureOpenAiApi:DeploymentName")); | |
// add our chat tool so its available if needed | |
chatCompletionOptions.Tools.Add(ChatToolService.CreateImageContextTool()); | |
var inputMessages = new List<ChatMessage> | |
{ | |
new SystemChatMessage("You are expert in image classification and analisys"), | |
}; | |
//perform initial api call to chatgpt | |
ChatCompletion completion = await chatClient.CompleteChatAsync(inputMessages, chatCompletionOptions); | |
//once completed we need to determine if we need to call a function tool like so: | |
if (completion.FinishReason == ChatFinishReason.ToolCalls) | |
// continued on the next code block... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment