Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageReference Include="Azure.Identity" Version="1.15.0" />
<PackageReference Include="Azure.Core" Version="1.49.0" />
<PackageReference Include="Azure.Identity" Version="1.16.0" />
<PackageReference Include="AwesomeAssertions" Version="9.1.0" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.9.0" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.9.0" />
Expand All @@ -23,6 +23,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.10.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.10.4" />
<PackageReference Include="OllamaSharp" Version="5.3.6" />
<PackageReference Include="OpenAI" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.ClientModel;
using System.ClientModel.Primitives;
using Azure;
using Azure.AI.Inference;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.AI.Evaluation;
Expand Down Expand Up @@ -76,10 +77,17 @@ private static ChatConfiguration GetAzureOpenAIChatConfiguration()
{
/// Get an instance of Microsoft.Extensions.AI's <see cref="IChatClient"/> interface for the selected LLM
/// endpoint.
IChatClient client =
new AzureOpenAIClient(new Uri(EnvironmentVariables.AzureOpenAIEndpoint), new DefaultAzureCredential())
.GetChatClient(EnvironmentVariables.AzureOpenAIModel)
.AsIChatClient();

// Append /openai/v1 suffix.
var endpoint = new Uri(new Uri(EnvironmentVariables.AzureOpenAIEndpoint), "/openai/v1");
var options = new OpenAIClientOptions { Endpoint = endpoint };

#pragma warning disable OPENAI001 // OpenAIClient(AuthenticationPolicy, OpenAIClientOptions) and GetChatClient(string) are experimental and subject to change or removal in future updates.
var policy = new BearerTokenPolicy(new DefaultAzureCredential(), "https://ai.azure.com/.default");
var openAIClient = new OpenAIClient(policy, options);

IChatClient client = openAIClient.GetChatClient(EnvironmentVariables.AzureOpenAIModel).AsIChatClient();
#pragma warning restore OPENAI001

/// Enable function invocation support.
client = client.AsBuilder().UseFunctionInvocation().Build();
Expand Down Expand Up @@ -112,10 +120,12 @@ private static ChatConfiguration GetOpenAIChatConfiguration()
{
/// Get an instance of Microsoft.Extensions.AI's <see cref="IChatClient"/> interface for the selected LLM
/// endpoint.
#pragma warning disable OPENAI001 // GetChatClient(string) is experimental and subject to change or removal in future updates.
IChatClient client =
new OpenAIClient(EnvironmentVariables.OpenAIAPIKey)
new OpenAIClient(new ApiKeyCredential(EnvironmentVariables.OpenAIAPIKey))
.GetChatClient(EnvironmentVariables.OpenAIModel)
.AsIChatClient();
#pragma warning restore OPENAI001

/// Enable function invocation support.
client = client.AsBuilder().UseFunctionInvocation().Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageReference Include="Azure.Identity" Version="1.15.0" />
<PackageReference Include="Azure.Core" Version="1.49.0" />
<PackageReference Include="Azure.Identity" Version="1.16.0" />
<PackageReference Include="AwesomeAssertions" Version="9.1.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.9" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.9.0" />
Expand All @@ -27,6 +27,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.10.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.10.4" />
<PackageReference Include="OllamaSharp" Version="5.3.6" />
<PackageReference Include="OpenAI" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down