Skip to content

Instantly share code, notes, and snippets.

@pavlovmilen
Last active September 21, 2024 17:41
Show Gist options
  • Save pavlovmilen/56a46cd5e7b0293a24c733d3d8374dca to your computer and use it in GitHub Desktop.
Save pavlovmilen/56a46cd5e7b0293a24c733d3d8374dca to your computer and use it in GitHub Desktop.
Chat client setup
// 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