Skip to content

Commit fdb5b25

Browse files
authored
Update Microsoft.Extensions.AI to 9.3.0-preview.1.25114.11 (#3656)
1 parent d8cf59a commit fdb5b25

9 files changed

+49
-40
lines changed

extensions/src/AWSSDK.Extensions.Bedrock.MEAI/AWSSDK.Extensions.Bedrock.MEAI.NetFramework.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</Choose>
3838

3939
<ItemGroup>
40-
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.1.0-preview.1.25064.3" />
40+
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25114.11" />
4141
</ItemGroup>
4242

4343
<ItemGroup>

extensions/src/AWSSDK.Extensions.Bedrock.MEAI/AWSSDK.Extensions.Bedrock.MEAI.NetStandard.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
</Choose>
4242

4343
<ItemGroup>
44-
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.1.0-preview.1.25064.3" />
44+
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25114.11" />
4545
</ItemGroup>
4646

4747
<ItemGroup>

extensions/src/AWSSDK.Extensions.Bedrock.MEAI/AWSSDK.Extensions.Bedrock.MEAI.nuspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
<group targetFramework="net472">
1616
<dependency id="AWSSDK.Core" version="4.0.0.0-preview.7" />
1717
<dependency id="AWSSDK.BedrockRuntime" version="4.0.0.0-preview.7" />
18-
<dependency id="Microsoft.Extensions.AI.Abstractions" version="9.1.0-preview.1.25064.3" />
18+
<dependency id="Microsoft.Extensions.AI.Abstractions" version="9.3.0-preview.1.25114.11" />
1919
</group>
2020
<group targetFramework="netstandard2.0">
2121
<dependency id="AWSSDK.Core" version="4.0.0.0-preview.7" />
2222
<dependency id="AWSSDK.BedrockRuntime" version="4.0.0.0-preview.7" />
23-
<dependency id="Microsoft.Extensions.AI.Abstractions" version="9.1.0-preview.1.25064.3" />
23+
<dependency id="Microsoft.Extensions.AI.Abstractions" version="9.3.0-preview.1.25114.11" />
2424
</group>
2525
<group targetFramework="net8.0">
2626
<dependency id="AWSSDK.Core" version="4.0.0.0-preview.7" />
2727
<dependency id="AWSSDK.BedrockRuntime" version="4.0.0.0-preview.7" />
28-
<dependency id="Microsoft.Extensions.AI.Abstractions" version="9.1.0-preview.1.25064.3" />
28+
<dependency id="Microsoft.Extensions.AI.Abstractions" version="9.3.0-preview.1.25114.11" />
2929
</group>
3030
</dependencies>
3131
</metadata>

extensions/src/AWSSDK.Extensions.Bedrock.MEAI/AmazonBedrockRuntimeExtensions.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,26 @@ public static class AmazonBedrockRuntimeExtensions
2828
/// <param name="runtime">The runtime instance to be represented as an <see cref="IChatClient"/>.</param>
2929
/// <param name="modelId">
3030
/// The default model ID to use when no model is specified in a request. If not specified,
31-
/// a model must be provided in the <see cref="ChatOptions.ModelId"/> passed to <see cref="IChatClient.CompleteAsync"/>
32-
/// or <see cref="IChatClient.CompleteStreamingAsync"/>.
31+
/// a model must be provided in the <see cref="ChatOptions.ModelId"/> passed to <see cref="IChatClient.GetResponseAsync"/>
32+
/// or <see cref="IChatClient.GetStreamingResponseAsync"/>.
3333
/// </param>
3434
/// <returns>A <see cref="IChatClient"/> instance representing the <see cref="IAmazonBedrockRuntime"/> instance.</returns>
3535
/// <exception cref="ArgumentNullException"><paramref name="runtime"/> is <see langword="null"/>.</exception>
3636
public static IChatClient AsChatClient(this IAmazonBedrockRuntime runtime, string? modelId = null) =>
3737
runtime is not null ? new BedrockChatClient(runtime, modelId) :
3838
throw new ArgumentNullException(nameof(runtime));
3939

40-
/// <summary>Gets an <see cref="IChatClient"/> for the specified <see cref="IAmazonBedrockRuntime"/> instance.</summary>
41-
/// <param name="runtime">The runtime instance to be represented as an <see cref="IChatClient"/>.</param>
40+
/// <summary>Gets an <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> for the specified <see cref="IAmazonBedrockRuntime"/> instance.</summary>
41+
/// <param name="runtime">The runtime instance to be represented as an <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/>.</param>
4242
/// <param name="modelId">
4343
/// The default model ID to use when no model is specified in a request. If not specified,
44-
/// a model must be provided in the <see cref="ChatOptions.ModelId"/> passed to <see cref="IChatClient.CompleteAsync"/>
45-
/// or <see cref="IChatClient.CompleteStreamingAsync"/>.
44+
/// a model must be provided in the <see cref="EmbeddingGenerationOptions.ModelId"/> passed to <see cref="IEmbeddingGenerator{TInput, TEmbedding}.GenerateAsync"/>.
4645
/// </param>
4746
/// <param name="dimensions">
4847
/// The default number of dimensions to request be generated. This will be overridden by a <see cref="EmbeddingGenerationOptions.Dimensions"/>
4948
/// if that is specified to a request. If neither is specified, the default for the model will be used.
5049
/// </param>
51-
/// <returns>A <see cref="IChatClient"/> instance representing the <see cref="IAmazonBedrockRuntime"/> instance.</returns>
50+
/// <returns>An <see cref="IEmbeddingGenerator{TInput, TEmbedding}"/> instance representing the <see cref="IAmazonBedrockRuntime"/> instance.</returns>
5251
/// <exception cref="ArgumentNullException"><paramref name="runtime"/> is <see langword="null"/>.</exception>
5352
public static IEmbeddingGenerator<string, Embedding<float>> AsEmbeddingGenerator(
5453
this IAmazonBedrockRuntime runtime, string? modelId = null, int? dimensions = null) =>

extensions/src/AWSSDK.Extensions.Bedrock.MEAI/BedrockChatClient.cs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ internal sealed partial class BedrockChatClient : IChatClient
3939
private readonly IAmazonBedrockRuntime _runtime;
4040
/// <summary>Default model ID to use when no model is specified in the request.</summary>
4141
private readonly string? _modelId;
42+
/// <summary>Metadata describing the chat client.</summary>
43+
private readonly ChatClientMetadata _metadata;
4244

4345
/// <summary>
4446
/// Initializes a new instance of the <see cref="BedrockChatClient"/> class.
@@ -52,7 +54,7 @@ public BedrockChatClient(IAmazonBedrockRuntime runtime, string? modelId)
5254
_runtime = runtime!;
5355
_modelId = modelId;
5456

55-
Metadata = new(AmazonBedrockRuntimeExtensions.ProviderName, modelId: modelId);
57+
_metadata = new(AmazonBedrockRuntimeExtensions.ProviderName, modelId: modelId);
5658
}
5759

5860
public void Dispose()
@@ -61,10 +63,7 @@ public void Dispose()
6163
}
6264

6365
/// <inheritdoc />
64-
public ChatClientMetadata Metadata { get; }
65-
66-
/// <inheritdoc />
67-
public async Task<ChatCompletion> CompleteAsync(
66+
public async Task<ChatResponse> GetResponseAsync(
6867
IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
6968
{
7069
if (chatMessages is null)
@@ -100,7 +99,7 @@ public async Task<ChatCompletion> CompleteAsync(
10099

101100
if (content.Image is { Source.Bytes: { } imageBytes, Format: { } imageFormat })
102101
{
103-
result.Contents.Add(new ImageContent(imageBytes.ToArray(), GetMimeType(imageFormat)));
102+
result.Contents.Add(new DataContent(imageBytes.ToArray(), GetMimeType(imageFormat)));
104103
}
105104

106105
if (content.Video is { Source.Bytes: { } videoBytes, Format: { } videoFormat })
@@ -125,7 +124,7 @@ public async Task<ChatCompletion> CompleteAsync(
125124
result.AdditionalProperties = new(responseFieldsDictionary);
126125
}
127126

128-
return new ChatCompletion(result)
127+
return new(result)
129128
{
130129
FinishReason = response.StopReason is not null ? GetChatFinishReason(response.StopReason) : null,
131130
Usage = response.Usage is TokenUsage usage ? new()
@@ -138,7 +137,7 @@ public async Task<ChatCompletion> CompleteAsync(
138137
}
139138

140139
/// <inheritdoc />
141-
public async IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAsync(
140+
public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
142141
IList<ChatMessage> chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
143142
{
144143
if (chatMessages is null)
@@ -254,15 +253,16 @@ public async IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAs
254253
}
255254

256255
/// <inheritdoc />
257-
public object? GetService(Type serviceType, object? key)
256+
public object? GetService(Type serviceType, object? serviceKey)
258257
{
259258
if (serviceType is null)
260259
{
261260
throw new ArgumentNullException(nameof(serviceType));
262261
}
263262

264263
return
265-
key is not null ? null :
264+
serviceKey is not null ? null :
265+
serviceType == typeof(ChatClientMetadata) ? _metadata :
266266
serviceType.IsInstanceOfType(_runtime) ? _runtime :
267267
serviceType.IsInstanceOfType(this) ? this :
268268
null;
@@ -342,7 +342,7 @@ private static List<ContentBlock> CreateContents(ChatMessage message)
342342
contents.Add(new() { Text = tc.Text });
343343
break;
344344

345-
case DataContent dc when dc.ContainsData:
345+
case DataContent dc when dc.Data.HasValue:
346346
if (GetImageFormat(dc.MediaType) is ImageFormat imageFormat)
347347
{
348348
contents.Add(new()
@@ -602,21 +602,28 @@ private static Document ToDocument(JsonElement json)
602602
Document inputs = default;
603603
List<Document> required = [];
604604

605-
foreach (var parameter in f.Metadata.Parameters)
605+
if (f.JsonSchema.TryGetProperty("properties", out JsonElement properties))
606+
{
607+
foreach (JsonProperty parameter in properties.EnumerateObject())
608+
{
609+
inputs.Add(parameter.Name, ToDocument(parameter.Value));
610+
}
611+
}
612+
613+
if (f.JsonSchema.TryGetProperty("required", out JsonElement requiredProperties))
606614
{
607-
inputs.Add(parameter.Name, parameter.Schema is JsonElement schema ? ToDocument(schema) : new Document(true));
608-
if (parameter.IsRequired)
615+
foreach (JsonElement requiredProperty in requiredProperties.EnumerateArray())
609616
{
610-
required.Add(parameter.Name);
617+
required.Add(requiredProperty.GetString());
611618
}
612619
}
613620

614621
return new Tool()
615622
{
616623
ToolSpec = new ToolSpecification()
617624
{
618-
Name = f.Metadata.Name,
619-
Description = !string.IsNullOrEmpty(f.Metadata.Description) ? f.Metadata.Description : f.Metadata.Name,
625+
Name = f.Name,
626+
Description = !string.IsNullOrEmpty(f.Description) ? f.Description : f.Name,
620627
InputSchema = new()
621628
{
622629
Json = new(new Dictionary<string, Document>()
@@ -636,6 +643,7 @@ private static Document ToDocument(JsonElement json)
636643
switch (options!.ToolMode)
637644
{
638645
case AutoChatToolMode:
646+
case null:
639647
choice = new ToolChoice() { Auto = new() };
640648
break;
641649

@@ -714,7 +722,7 @@ private static Document CreateAdditionalModelRequestFields(ChatOptions? options)
714722
}
715723
catch (Exception e)
716724
{
717-
DefaultLogger.Debug(e, "Unable to serialize ChatOptions.AdditionalProperties[\"{PropertyName}\"] of type {PropertyType}", prop.Key, prop.Value?.GetType());
725+
DefaultLogger.Debug(e, "Unable to serialize ChatOptions.AdditionalProperties[\"{0}\"] of type {1}", prop.Key, prop.Value?.GetType());
718726
}
719727
break;
720728
}

extensions/src/AWSSDK.Extensions.Bedrock.MEAI/BedrockEmbeddingGenerator.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ internal sealed partial class BedrockEmbeddingGenerator : IEmbeddingGenerator<st
3232
private readonly string? _modelId;
3333
/// <summary>Default number of dimensions to use when no number of dimensions is specified in the request.</summary>
3434
private readonly int? _dimensions;
35+
/// <summary>Metadata describing the embedding generator.</summary>
36+
private readonly EmbeddingGeneratorMetadata _metadata;
3537

3638
/// <summary>
3739
/// Initializes a new instance of the <see cref="BedrockEmbeddingGenerator"/> class.
@@ -47,7 +49,7 @@ public BedrockEmbeddingGenerator(IAmazonBedrockRuntime runtime, string? modelId,
4749
_modelId = modelId;
4850
_dimensions = dimensions;
4951

50-
Metadata = new(AmazonBedrockRuntimeExtensions.ProviderName, modelId: modelId, dimensions: dimensions);
52+
_metadata = new(AmazonBedrockRuntimeExtensions.ProviderName, modelId: modelId, dimensions: dimensions);
5153
}
5254

5355
public void Dispose()
@@ -56,18 +58,18 @@ public void Dispose()
5658
}
5759

5860
/// <inheritdoc />
59-
public EmbeddingGeneratorMetadata Metadata { get; }
6061

6162
/// <inheritdoc />
62-
public object? GetService(Type serviceType, object? key)
63+
public object? GetService(Type serviceType, object? serviceKey)
6364
{
6465
if (serviceType is null)
6566
{
6667
throw new ArgumentNullException(nameof(serviceType));
6768
}
6869

6970
return
70-
key is not null ? null :
71+
serviceKey is not null ? null :
72+
serviceType == typeof(EmbeddingGeneratorMetadata) ? _metadata :
7173
serviceType.IsInstanceOfType(_runtime) ? _runtime :
7274
serviceType.IsInstanceOfType(this) ? this :
7375
null;

extensions/test/BedrockMEAITests/BedrockChatClientTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public void AsChatClient_ReturnsInstance(string modelId)
2323
IChatClient client = runtime.AsChatClient(modelId);
2424

2525
Assert.NotNull(client);
26-
Assert.Equal("aws.bedrock", client.Metadata.ProviderName);
27-
Assert.Equal(modelId, client.Metadata.ModelId);
26+
Assert.Equal("aws.bedrock", client.GetService<ChatClientMetadata>()?.ProviderName);
27+
Assert.Equal(modelId, client.GetService<ChatClientMetadata>()?.ModelId);
2828
}
2929

3030
[Fact]

extensions/test/BedrockMEAITests/BedrockEmbeddingGeneratorTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public void AsEmbeddingGenerator_ReturnsInstance(string modelId, int? dimensions
2525
IEmbeddingGenerator<string, Embedding<float>> generator = runtime.AsEmbeddingGenerator(modelId, dimensions);
2626

2727
Assert.NotNull(generator);
28-
Assert.Equal("aws.bedrock", generator.Metadata.ProviderName);
29-
Assert.Equal(modelId, generator.Metadata.ModelId);
30-
Assert.Equal(dimensions, generator.Metadata.Dimensions);
28+
Assert.Equal("aws.bedrock", generator.GetService<EmbeddingGeneratorMetadata>()?.ProviderName);
29+
Assert.Equal(modelId, generator.GetService<EmbeddingGeneratorMetadata>()?.ModelId);
30+
Assert.Equal(dimensions, generator.GetService<EmbeddingGeneratorMetadata>()?.Dimensions);
3131
}
3232

3333
[Fact]

extensions/test/BedrockMEAITests/BedrockMEAITests.NetFramework.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</PropertyGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.1.0-preview.1.25064.3" />
21+
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25114.11" />
2222
<PackageReference Include="xunit" Version="2.9.2" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
2424
</ItemGroup>

0 commit comments

Comments
 (0)