Visitar URL original
Remove Azure.AI.OpenAI dependency from templates and tests by Copilot · Pull Request #6873 · dotnet/extensions · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove Azure.AI.OpenAI package references from test projects
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
  • Loading branch information
Copilot and stephentoub committed Oct 4, 2025
commit 5bd6d4d79847278494a0b253e294345dc41fc39f
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Core" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
<PackageReference Include="OpenAI" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

using System;
using System.ClientModel;
using Azure.AI.OpenAI;
using Azure.Core;
using Azure.Identity;
using OpenAI;

namespace Microsoft.Extensions.AI.Evaluation.Integration.Tests;

Expand All @@ -15,22 +16,42 @@ internal static class Setup

internal static ChatConfiguration CreateChatConfiguration()
{
AzureOpenAIClient azureOpenAIClient = GetAzureOpenAIClient();
IChatClient chatClient = azureOpenAIClient.GetChatClient(Settings.Current.DeploymentName).AsIChatClient();
OpenAI.Chat.ChatClient openAIClient = GetOpenAIClient();
IChatClient chatClient = openAIClient.AsIChatClient();
return new ChatConfiguration(chatClient);
}

private static AzureOpenAIClient GetAzureOpenAIClient()
private static OpenAI.Chat.ChatClient GetOpenAIClient()
{
var endpoint = new Uri(Settings.Current.Endpoint);
AzureOpenAIClientOptions options = new();
// Use Azure endpoint with /openai/v1 suffix
Comment thread
stephentoub marked this conversation as resolved.
Resolved
var endpoint = new Uri(new Uri(Settings.Current.Endpoint), "/openai/v1");
var credential = new ChainedTokenCredential(new AzureCliCredential(), new DefaultAzureCredential());

AzureOpenAIClient azureOpenAIClient =
OfflineOnly
? new AzureOpenAIClient(endpoint, new ApiKeyCredential("Bogus"), options)
: new AzureOpenAIClient(endpoint, credential, options);
OpenAIClient client = OfflineOnly
? new OpenAIClient(endpoint, new ApiKeyCredential("Bogus"))
: new OpenAIClient(endpoint, new AzureTokenCredentialWrapper(credential));

return azureOpenAIClient;
return client.GetChatClient(Settings.Current.DeploymentName);
}

/// <summary>Wraps an Azure TokenCredential for use with OpenAI client.</summary>
private sealed class AzureTokenCredentialWrapper : ApiKeyCredential
{
private readonly TokenCredential _tokenCredential;

public AzureTokenCredentialWrapper(TokenCredential tokenCredential)
: base("placeholder")
{
_tokenCredential = tokenCredential;
}

public override void Deconstruct(out string key)
{
// Get Azure token and use it as the API key
var token = _tokenCredential.GetToken(
new TokenRequestContext(["https://cognitiveservices.azure.com/.default"]),
default);
key = token.Token;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.ClientModel;
using Azure.AI.OpenAI;
using Azure.Core;
using Azure.Identity;
using OpenAI;

Expand All @@ -25,13 +25,18 @@ internal static class IntegrationTestHelpers
var endpoint = configuration["OpenAI:Endpoint"]
?? throw new InvalidOperationException("To use AzureOpenAI, set a value for OpenAI:Endpoint");

// Use Azure endpoint with /openai/v1 suffix
var azureEndpointUri = new Uri(new Uri(endpoint), "/openai/v1");

if (apiKey is not null)
{
return new AzureOpenAIClient(new Uri(endpoint), new ApiKeyCredential(apiKey));
return new OpenAIClient(azureEndpointUri, new ApiKeyCredential(apiKey));
}
else
{
return new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential());
// Use Azure Identity authentication
var tokenCredential = new DefaultAzureCredential();
return new OpenAIClient(azureEndpointUri, new AzureTokenCredentialWrapper(tokenCredential));
}
}
else if (apiKey is not null)
Expand All @@ -41,4 +46,25 @@ internal static class IntegrationTestHelpers

return null;
}

/// <summary>Wraps an Azure TokenCredential for use with OpenAI client.</summary>
private sealed class AzureTokenCredentialWrapper : ApiKeyCredential
{
private readonly TokenCredential _tokenCredential;

public AzureTokenCredentialWrapper(TokenCredential tokenCredential)
: base("placeholder")
{
_tokenCredential = tokenCredential;
}

public override void Deconstruct(out string key)
{
// Get Azure token and use it as the API key
var token = _tokenCredential.GetToken(
new TokenRequestContext(["https://cognitiveservices.azure.com/.default"]),
default);
key = token.Token;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Core" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="PdfPig" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.3.0-beta.2" />
<PackageReference Include="Aspire.Azure.AI.OpenAI" Version="9.5.0-preview.1.25474.7" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.10.0" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.10.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.3.0-beta.2" />
<PackageReference Include="Aspire.Azure.AI.OpenAI" Version="9.5.0-preview.1.25474.7" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.10.0" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.10.0" />
Expand Down