Skip to content

.Net: AzureOpenAI with DefaultAzureCredential sample #7527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions dotnet/samples/Concepts/ChatCompletion/OpenAI_ChatCompletion.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using Azure.Identity;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;

Expand All @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -60,6 +61,24 @@ public async Task AzureOpenAIChatSampleAsync()
await StartChatAsync(chatCompletionService);
}

/// <summary>
/// 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.
/// </summary>
[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:");
Expand Down
Loading