-
Couldn't load subscription status.
- Fork 287
Add AI support to the Microsoft.Testing.Platform
#6777
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
base: main
Are you sure you want to change the base?
Changes from 12 commits
896004a
3ead977
52922ee
aa40dad
9a0cc8e
62473bb
7e99cf9
a2ec275
30bfac1
4816d44
6ce7fda
7135242
ac4f580
68be1df
d16c442
aa12146
8a4116a
bfcdbf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>netstandard2.0;$(SupportedNetFrameworks)</TargetFrameworks> | ||
| <IsShipping>false</IsShipping> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- NuGet package layout --> | ||
| <!-- NuGet folders https://learn.microsoft.com/nuget/create-packages/creating-a-package#from-a-convention-based-working-directory --> | ||
| <ItemGroup> | ||
| <Content Include="buildMultiTargeting/**"> | ||
MarcoRossignoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Pack>true</Pack> | ||
| <PackagePath>buildMultiTargeting</PackagePath> | ||
| </Content> | ||
| <TfmSpecificPackageFile Include="buildTransitive/**"> | ||
| <PackagePath>buildTransitive/$(TargetFramework)</PackagePath> | ||
| </TfmSpecificPackageFile> | ||
| <TfmSpecificPackageFile Include="build/**"> | ||
| <PackagePath>build/$(TargetFramework)</PackagePath> | ||
| </TfmSpecificPackageFile> | ||
MarcoRossignoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Azure.AI.OpenAI" /> | ||
| <PackageReference Include="Microsoft.Extensions.AI.OpenAI" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Platform.AI\Microsoft.Testing.Platform.AI.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.ClientModel; | ||
|
|
||
| using Azure.AI.OpenAI; | ||
|
|
||
| using Microsoft.Extensions.AI; | ||
| using Microsoft.Testing.Extensions.AzureFoundry.Resources; | ||
| using Microsoft.Testing.Platform.AI; | ||
| using Microsoft.Testing.Platform.Helpers; | ||
| using Microsoft.Testing.Platform.Services; | ||
|
|
||
| namespace Microsoft.Testing.Extensions.AzureFoundry; | ||
|
|
||
| /// <summary> | ||
| /// Provider for creating Azure OpenAI chat clients. | ||
| /// </summary> | ||
| internal sealed class AzureOpenAIChatClientProvider : IChatClientProvider | ||
| { | ||
| private readonly IEnvironment _environment; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AzureOpenAIChatClientProvider"/> class. | ||
| /// </summary> | ||
| /// <param name="serviceProvider">The service provider.</param> | ||
| internal AzureOpenAIChatClientProvider(IServiceProvider serviceProvider) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would take IEnvironment here. It's easier to grasp what the service needs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's all internal but it's fine I'll update the ctor |
||
| { | ||
| _environment = serviceProvider.GetRequiredService<IEnvironment>(); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public bool SupportsToolCalling => true; | ||
|
|
||
| /// <inheritdoc /> | ||
| public string ModelName => _environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "unknown"; | ||
|
|
||
| /// <inheritdoc /> | ||
| public Task<IChatClient> CreateChatClientAsync(CancellationToken cancellationToken) | ||
| { | ||
| string? endpoint = _environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); | ||
| string? deploymentName = _environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME"); | ||
| string? apiKey = _environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY"); | ||
|
|
||
| if (string.IsNullOrEmpty(endpoint)) | ||
| { | ||
| throw new InvalidOperationException(ExtensionResources.AzureOpenAIEndpointNotSet); | ||
| } | ||
|
|
||
| if (string.IsNullOrEmpty(deploymentName)) | ||
| { | ||
| throw new InvalidOperationException(ExtensionResources.AzureOpenAIDeploymentNameNotSet); | ||
| } | ||
|
|
||
| if (string.IsNullOrEmpty(apiKey)) | ||
| { | ||
| throw new InvalidOperationException(ExtensionResources.AzureOpenAIApiKeyNotSet); | ||
| } | ||
|
|
||
| var client = new AzureOpenAIClient( | ||
| new Uri(endpoint!), | ||
| new ApiKeyCredential(apiKey!)); | ||
|
|
||
| return Task.FromResult(client.GetChatClient(deploymentName).AsIChatClient()); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.