diff --git a/dotnet/samples/Concepts/ChatCompletion/OpenAI_ChatCompletion.cs b/dotnet/samples/Concepts/ChatCompletion/OpenAI_ChatCompletion.cs index 22b6eec9baaf..46aadfc243b0 100644 --- a/dotnet/samples/Concepts/ChatCompletion/OpenAI_ChatCompletion.cs +++ b/dotnet/samples/Concepts/ChatCompletion/OpenAI_ChatCompletion.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. +using Azure.Identity; using Microsoft.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel.Connectors.OpenAI; @@ -11,7 +12,7 @@ public class OpenAI_ChatCompletion(ITestOutputHelper output) : BaseTest(output) [Fact] public async Task OpenAIChatSampleAsync() { - Console.WriteLine("======== Open AI - ChatGPT ========"); + Console.WriteLine("======== Open AI - Chat Completion ========"); OpenAIChatCompletionService chatCompletionService = new(TestConfiguration.OpenAI.ChatModelId, TestConfiguration.OpenAI.ApiKey); @@ -49,7 +50,7 @@ I hope these suggestions are helpful! [Fact] public async Task AzureOpenAIChatSampleAsync() { - Console.WriteLine("======== Azure Open AI - ChatGPT ========"); + Console.WriteLine("======== Azure Open AI - Chat Completion ========"); AzureOpenAIChatCompletionService chatCompletionService = new( deploymentName: TestConfiguration.AzureOpenAI.ChatDeploymentName, @@ -60,6 +61,24 @@ public async Task AzureOpenAIChatSampleAsync() await StartChatAsync(chatCompletionService); } + /// + /// Sample showing how to use Azure Open AI Chat Completion with Azure Default Credential. + /// If local auth is disabled in the Azure Open AI deployment, you can use Azure Default Credential to authenticate. + /// + [Fact] + public async Task AzureOpenAIWithDefaultAzureCredentialSampleAsync() + { + Console.WriteLine("======== Azure Open AI - Chat Completion with Azure Default Credential ========"); + + AzureOpenAIChatCompletionService chatCompletionService = new( + deploymentName: TestConfiguration.AzureOpenAI.ChatDeploymentName, + endpoint: TestConfiguration.AzureOpenAI.Endpoint, + credentials: new DefaultAzureCredential(), + modelId: TestConfiguration.AzureOpenAI.ChatModelId); + + await StartChatAsync(chatCompletionService); + } + private async Task StartChatAsync(IChatCompletionService chatGPT) { Console.WriteLine("Chat content:");