Skip to content

Commit 268a7f9

Browse files
stephentoubpeterrsongg
authored andcommitted
Implement Microsoft.Extensions.AI's IChatClient / IEmbeddingGenerator for IAmazonBedrockRuntime (#3545)
* Implement Microsoft.Extensions.AI's IChatClient on AmazonBedrockRuntimeClient This enables AmazonBedrockRuntimeClient to be used as a Microsoft.Extensions.AI.IChatClient, such that it can implicitly be used by any consumer that operates on an IChatClient, and with any middleware written in terms of IChatClient, such as those components in the Microsoft.Extensions.AI package that provide support for automatic function invocation, OpenTelemetry, logging, distributed caching, and more.
1 parent af13bc7 commit 268a7f9

17 files changed

+1368
-7
lines changed

extensions/AWSSDK.Extensions.sln

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,28 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudFront.Signers.Tests.Ne
3636
EndProject
3737
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC2.DecryptPassword.NetStandard", "test\EC2.DecryptPasswordTests\EC2.DecryptPassword.NetStandard.csproj", "{EA6EEC77-E69B-4D42-B9F2-BADCEEE5A32B}"
3838
EndProject
39-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.CloudFront.NetStandard", "..\sdk\src\Services\CloudFront\AWSSDK.CloudFront.NetStandard.csproj", "{280223DF-ECB0-4B38-A3A6-B80B46D48475}"
39+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BedrockMEAITests.NetFramework", "test\BedrockMEAITests\BedrockMEAITests.NetFramework.csproj", "{D98D6380-80A3-4818-84B4-3BD332383CA2}"
40+
EndProject
41+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.BedrockRuntime.NetStandard", "..\sdk\src\Services\BedrockRuntime\AWSSDK.BedrockRuntime.NetStandard.csproj", "{280223DF-ECB0-4B38-A3A6-B80B46D48475}"
42+
EndProject
43+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.CloudFront.NetStandard", "..\sdk\src\Services\CloudFront\AWSSDK.CloudFront.NetStandard.csproj", "{71C8FC92-F868-4E07-B005-62180C1D6B8B}"
4044
EndProject
4145
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.EC2.NetStandard", "..\sdk\src\Services\EC2\AWSSDK.EC2.NetStandard.csproj", "{FC70CF98-BA7E-4F9F-A5DB-966973284091}"
4246
EndProject
43-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.CloudFront.NetFramework", "..\sdk\src\Services\CloudFront\AWSSDK.CloudFront.NetFramework.csproj", "{4FFF9872-1D77-4664-83C6-B46AC6EB1E20}"
47+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.BedrockRuntime.NetFramework", "..\sdk\src\Services\BedrockRuntime\AWSSDK.BedrockRuntime.NetFramework.csproj", "{4FFF9872-1D77-4664-83C6-B46AC6EB1E20}"
48+
EndProject
49+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.CloudFront.NetFramework", "..\sdk\src\Services\CloudFront\AWSSDK.CloudFront.NetFramework.csproj", "{B416F870-421E-410A-8848-13A7F523E669}"
4450
EndProject
4551
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.EC2.NetFramework", "..\sdk\src\Services\EC2\AWSSDK.EC2.NetFramework.csproj", "{0377B228-91F3-4A0B-BE66-221E7ECA6DF7}"
4652
EndProject
4753
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.CloudFront.Signers.NetFramework", "src\AWSSDK.Extensions.CloudFront.Signers\AWSSDK.Extensions.CloudFront.Signers.NetFramework.csproj", "{E195094D-5899-4FDF-969D-93C4432BA921}"
4854
EndProject
4955
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.EC2.DecryptPassword.NetFramework", "src\AWSSDK.Extensions.EC2.DecryptPassword\AWSSDK.Extensions.EC2.DecryptPassword.NetFramework.csproj", "{3EC669E6-A541-445E-B68E-0A853715E39C}"
5056
EndProject
57+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.Bedrock.MEAI.NetFramework", "src\AWSSDK.Extensions.Bedrock.MEAI\AWSSDK.Extensions.Bedrock.MEAI.NetFramework.csproj", "{4A94F623-0C71-47BD-B927-CB6FA28D33A1}"
58+
EndProject
59+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.Bedrock.MEAI.NetStandard", "src\AWSSDK.Extensions.Bedrock.MEAI\AWSSDK.Extensions.Bedrock.MEAI.NetStandard.csproj", "{B174860A-0D1B-4B7D-9E46-7DBFC9AA5AAB}"
60+
EndProject
5161
Global
5262
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5363
Debug|Any CPU = Debug|Any CPU
@@ -102,10 +112,22 @@ Global
102112
{EA6EEC77-E69B-4D42-B9F2-BADCEEE5A32B}.Debug|Any CPU.Build.0 = Debug|Any CPU
103113
{EA6EEC77-E69B-4D42-B9F2-BADCEEE5A32B}.Release|Any CPU.ActiveCfg = Release|Any CPU
104114
{EA6EEC77-E69B-4D42-B9F2-BADCEEE5A32B}.Release|Any CPU.Build.0 = Release|Any CPU
115+
{B5244288-5997-4E72-8AD8-936D346C02CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
116+
{B5244288-5997-4E72-8AD8-936D346C02CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
117+
{B5244288-5997-4E72-8AD8-936D346C02CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
118+
{B5244288-5997-4E72-8AD8-936D346C02CE}.Release|Any CPU.Build.0 = Release|Any CPU
119+
{D98D6380-80A3-4818-84B4-3BD332383CA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
120+
{D98D6380-80A3-4818-84B4-3BD332383CA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
121+
{D98D6380-80A3-4818-84B4-3BD332383CA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
122+
{D98D6380-80A3-4818-84B4-3BD332383CA2}.Release|Any CPU.Build.0 = Release|Any CPU
105123
{280223DF-ECB0-4B38-A3A6-B80B46D48475}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
106124
{280223DF-ECB0-4B38-A3A6-B80B46D48475}.Debug|Any CPU.Build.0 = Debug|Any CPU
107125
{280223DF-ECB0-4B38-A3A6-B80B46D48475}.Release|Any CPU.ActiveCfg = Release|Any CPU
108126
{280223DF-ECB0-4B38-A3A6-B80B46D48475}.Release|Any CPU.Build.0 = Release|Any CPU
127+
{71C8FC92-F868-4E07-B005-62180C1D6B8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
128+
{71C8FC92-F868-4E07-B005-62180C1D6B8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
129+
{71C8FC92-F868-4E07-B005-62180C1D6B8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
130+
{71C8FC92-F868-4E07-B005-62180C1D6B8B}.Release|Any CPU.Build.0 = Release|Any CPU
109131
{FC70CF98-BA7E-4F9F-A5DB-966973284091}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
110132
{FC70CF98-BA7E-4F9F-A5DB-966973284091}.Debug|Any CPU.Build.0 = Debug|Any CPU
111133
{FC70CF98-BA7E-4F9F-A5DB-966973284091}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -114,6 +136,10 @@ Global
114136
{4FFF9872-1D77-4664-83C6-B46AC6EB1E20}.Debug|Any CPU.Build.0 = Debug|Any CPU
115137
{4FFF9872-1D77-4664-83C6-B46AC6EB1E20}.Release|Any CPU.ActiveCfg = Release|Any CPU
116138
{4FFF9872-1D77-4664-83C6-B46AC6EB1E20}.Release|Any CPU.Build.0 = Release|Any CPU
139+
{B416F870-421E-410A-8848-13A7F523E669}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
140+
{B416F870-421E-410A-8848-13A7F523E669}.Debug|Any CPU.Build.0 = Debug|Any CPU
141+
{B416F870-421E-410A-8848-13A7F523E669}.Release|Any CPU.ActiveCfg = Release|Any CPU
142+
{B416F870-421E-410A-8848-13A7F523E669}.Release|Any CPU.Build.0 = Release|Any CPU
117143
{0377B228-91F3-4A0B-BE66-221E7ECA6DF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
118144
{0377B228-91F3-4A0B-BE66-221E7ECA6DF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
119145
{0377B228-91F3-4A0B-BE66-221E7ECA6DF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -126,6 +152,14 @@ Global
126152
{3EC669E6-A541-445E-B68E-0A853715E39C}.Debug|Any CPU.Build.0 = Debug|Any CPU
127153
{3EC669E6-A541-445E-B68E-0A853715E39C}.Release|Any CPU.ActiveCfg = Release|Any CPU
128154
{3EC669E6-A541-445E-B68E-0A853715E39C}.Release|Any CPU.Build.0 = Release|Any CPU
155+
{4A94F623-0C71-47BD-B927-CB6FA28D33A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
156+
{4A94F623-0C71-47BD-B927-CB6FA28D33A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
157+
{4A94F623-0C71-47BD-B927-CB6FA28D33A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
158+
{4A94F623-0C71-47BD-B927-CB6FA28D33A1}.Release|Any CPU.Build.0 = Release|Any CPU
159+
{B174860A-0D1B-4B7D-9E46-7DBFC9AA5AAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
160+
{B174860A-0D1B-4B7D-9E46-7DBFC9AA5AAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
161+
{B174860A-0D1B-4B7D-9E46-7DBFC9AA5AAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
162+
{B174860A-0D1B-4B7D-9E46-7DBFC9AA5AAB}.Release|Any CPU.Build.0 = Release|Any CPU
129163
EndGlobalSection
130164
GlobalSection(SolutionProperties) = preSolution
131165
HideSolutionNode = FALSE
@@ -143,12 +177,18 @@ Global
143177
{C8A027AB-282C-400E-893D-971A5D55DB17} = {3D822DC2-ED2E-4434-BC4F-CE7FCD846B02}
144178
{A552BA51-D17C-4594-BF0A-DF7F53EA688D} = {A960D001-40B3-4B1A-A890-D1049FB7586E}
145179
{EA6EEC77-E69B-4D42-B9F2-BADCEEE5A32B} = {A960D001-40B3-4B1A-A890-D1049FB7586E}
180+
{B5244288-5997-4E72-8AD8-936D346C02CE} = {A960D001-40B3-4B1A-A890-D1049FB7586E}
181+
{D98D6380-80A3-4818-84B4-3BD332383CA2} = {A960D001-40B3-4B1A-A890-D1049FB7586E}
146182
{280223DF-ECB0-4B38-A3A6-B80B46D48475} = {0BA39F07-84D6-420B-82D3-6DC3AF016C65}
183+
{71C8FC92-F868-4E07-B005-62180C1D6B8B} = {0BA39F07-84D6-420B-82D3-6DC3AF016C65}
147184
{FC70CF98-BA7E-4F9F-A5DB-966973284091} = {0BA39F07-84D6-420B-82D3-6DC3AF016C65}
148185
{4FFF9872-1D77-4664-83C6-B46AC6EB1E20} = {0BA39F07-84D6-420B-82D3-6DC3AF016C65}
186+
{B416F870-421E-410A-8848-13A7F523E669} = {0BA39F07-84D6-420B-82D3-6DC3AF016C65}
149187
{0377B228-91F3-4A0B-BE66-221E7ECA6DF7} = {0BA39F07-84D6-420B-82D3-6DC3AF016C65}
150188
{E195094D-5899-4FDF-969D-93C4432BA921} = {3D822DC2-ED2E-4434-BC4F-CE7FCD846B02}
151189
{3EC669E6-A541-445E-B68E-0A853715E39C} = {3D822DC2-ED2E-4434-BC4F-CE7FCD846B02}
190+
{4A94F623-0C71-47BD-B927-CB6FA28D33A1} = {3D822DC2-ED2E-4434-BC4F-CE7FCD846B02}
191+
{B174860A-0D1B-4B7D-9E46-7DBFC9AA5AAB} = {3D822DC2-ED2E-4434-BC4F-CE7FCD846B02}
152192
EndGlobalSection
153193
GlobalSection(ExtensibilityGlobals) = postSolution
154194
SolutionGuid = {949367A4-5683-4FD3-93F4-A2CEA6EECB21}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net472</TargetFramework>
4+
<AssemblyName>AWSSDK.Extensions.Bedrock.MEAI</AssemblyName>
5+
<PackageId>AWSSDK.Extensions.Bedrock.MEAI</PackageId>
6+
7+
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
8+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
9+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
10+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
11+
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
12+
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
13+
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
14+
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
15+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
16+
17+
<LangVersion>Latest</LangVersion>
18+
<Nullable>enable</Nullable>
19+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
20+
</PropertyGroup>
21+
22+
<ItemGroup>
23+
<Compile Remove="**/obj/**" />
24+
</ItemGroup>
25+
26+
<Choose>
27+
<When Condition=" '$(AWSKeyFile)' == '' ">
28+
<PropertyGroup>
29+
<AssemblyOriginatorKeyFile>..\..\..\sdk\awssdk.dll.snk</AssemblyOriginatorKeyFile>
30+
</PropertyGroup>
31+
</When>
32+
<Otherwise>
33+
<PropertyGroup>
34+
<AssemblyOriginatorKeyFile>$(AWSKeyFile)</AssemblyOriginatorKeyFile>
35+
</PropertyGroup>
36+
</Otherwise>
37+
</Choose>
38+
39+
<ItemGroup>
40+
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.0.1-preview.1.24570.5" />
41+
</ItemGroup>
42+
43+
<ItemGroup>
44+
<ProjectReference Include="../../../sdk/src/Core/AWSSDK.Core.NetFramework.csproj" />
45+
<ProjectReference Include="../../../sdk/src/Services/BedrockRuntime/AWSSDK.BedrockRuntime.NetFramework.csproj" />
46+
</ItemGroup>
47+
</Project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
4+
<AssemblyName>AWSSDK.Extensions.Bedrock.MEAI</AssemblyName>
5+
<PackageId>AWSSDK.Extensions.Bedrock.MEAI</PackageId>
6+
7+
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
8+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
9+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
10+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
11+
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
12+
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
13+
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
14+
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
15+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
16+
17+
<LangVersion>Latest</LangVersion>
18+
<Nullable>enable</Nullable>
19+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
20+
</PropertyGroup>
21+
22+
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
23+
<IsTrimmable>true</IsTrimmable>
24+
</PropertyGroup>
25+
26+
<ItemGroup>
27+
<Compile Remove="**/obj/**" />
28+
</ItemGroup>
29+
30+
<Choose>
31+
<When Condition=" '$(AWSKeyFile)' == '' ">
32+
<PropertyGroup>
33+
<AssemblyOriginatorKeyFile>..\..\..\sdk\awssdk.dll.snk</AssemblyOriginatorKeyFile>
34+
</PropertyGroup>
35+
</When>
36+
<Otherwise>
37+
<PropertyGroup>
38+
<AssemblyOriginatorKeyFile>$(AWSKeyFile)</AssemblyOriginatorKeyFile>
39+
</PropertyGroup>
40+
</Otherwise>
41+
</Choose>
42+
43+
<ItemGroup>
44+
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.0.1-preview.1.24570.5" />
45+
</ItemGroup>
46+
47+
<ItemGroup>
48+
<ProjectReference Include="../../../sdk/src/Core/AWSSDK.Core.NetStandard.csproj" />
49+
<ProjectReference Include="../../../sdk/src/Services/BedrockRuntime/AWSSDK.BedrockRuntime.NetStandard.csproj" />
50+
</ItemGroup>
51+
</Project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package>
3+
<metadata>
4+
<id>AWSSDK.Extensions.Bedrock.MEAI</id>
5+
<title>AWSSDK - Bedrock integration with Microsoft.Extensions.AI.</title>
6+
<version>4.0.0.0-preview.4</version>
7+
<authors>Amazon Web Services</authors>
8+
<description>Implementations of Microsoft.Extensions.AI's abstractions for Bedrock.</description>
9+
<language>en-US</language>
10+
<license type="expression">Apache-2.0</license>
11+
<projectUrl>https://github.com/aws/aws-sdk-net/</projectUrl>
12+
<tags>AWS Amazon aws-sdk-v4</tags>
13+
<icon>images\AWSLogo.png</icon>
14+
<dependencies>
15+
<group targetFramework="net472">
16+
<dependency id="AWSSDK.Core" version="4.0.0.0-preview.4" />
17+
<dependency id="Microsoft.Extensions.AI.Abstractions" version="9.0.1-preview.1.24570.5" />
18+
</group>
19+
<group targetFramework="netstandard2.0">
20+
<dependency id="AWSSDK.Core" version="4.0.0.0-preview.4" />
21+
<dependency id="Microsoft.Extensions.AI.Abstractions" version="9.0.1-preview.1.24570.5" />
22+
</group>
23+
<group targetFramework="net8.0">
24+
<dependency id="AWSSDK.Core" version="4.0.0.0-preview.4" />
25+
<dependency id="Microsoft.Extensions.AI.Abstractions" version="9.0.1-preview.1.24570.5" />
26+
</group>
27+
</dependencies>
28+
</metadata>
29+
<files>
30+
<file src="..\..\..\sdk\nuget-content\AWSLogo.png" target="images\" />
31+
32+
<file src=".\bin\Release\net472\AWSSDK.Extensions.Bedrock.MEAI.dll" target="lib\net472" />
33+
<file src=".\bin\Release\net472\AWSSDK.Extensions.Bedrock.MEAI.pdb" target="lib\net472" />
34+
<file src=".\bin\Release\net472\AWSSDK.Extensions.Bedrock.MEAI.xml" target="lib\net472" />
35+
36+
<file src=".\bin\Release\netstandard2.0\AWSSDK.Extensions.Bedrock.MEAI.dll" target="lib\netstandard2.0"/>
37+
<file src=".\bin\Release\netstandard2.0\AWSSDK.Extensions.Bedrock.MEAI.pdb" target="lib\netstandard2.0"/>
38+
<file src=".\bin\Release\netstandard2.0\AWSSDK.Extensions.Bedrock.MEAI.xml" target="lib\netstandard2.0" />
39+
40+
<file src=".\bin\Release\net8.0\AWSSDK.Extensions.Bedrock.MEAI.dll" target="lib\net8.0" />
41+
<file src=".\bin\Release\net8.0\AWSSDK.Extensions.Bedrock.MEAI.pdb" target="lib\net8.0" />
42+
<file src=".\bin\Release\net8.0\AWSSDK.Extensions.Bedrock.MEAI.xml" target="lib\net8.0" />
43+
</files>
44+
</package>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
using Microsoft.Extensions.AI;
17+
using System;
18+
19+
namespace Amazon.BedrockRuntime;
20+
21+
/// <summary>Provides extensions for working with <see cref="IAmazonBedrockRuntime"/> instances.</summary>
22+
public static class AmazonBedrockRuntimeExtensions
23+
{
24+
/// <summary>The provider name to use in metadata.</summary>
25+
internal const string ProviderName = "aws.bedrock";
26+
27+
/// <summary>Gets an <see cref="IChatClient"/> for the specified <see cref="IAmazonBedrockRuntime"/> instance.</summary>
28+
/// <param name="runtime">The runtime instance to be represented as an <see cref="IChatClient"/>.</param>
29+
/// <param name="modelId">
30+
/// 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"/>.
33+
/// </param>
34+
/// <returns>A <see cref="IChatClient"/> instance representing the <see cref="IAmazonBedrockRuntime"/> instance.</returns>
35+
/// <exception cref="ArgumentNullException"><paramref name="runtime"/> is <see langword="null"/>.</exception>
36+
public static IChatClient AsChatClient(this IAmazonBedrockRuntime runtime, string? modelId = null) =>
37+
runtime is not null ? new BedrockChatClient(runtime, modelId) :
38+
throw new ArgumentNullException(nameof(runtime));
39+
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>
42+
/// <param name="modelId">
43+
/// 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"/>.
46+
/// </param>
47+
/// <param name="dimensions">
48+
/// The default number of dimensions to request be generated. This will be overridden by a <see cref="EmbeddingGenerationOptions.Dimensions"/>
49+
/// if that is specified to a request. If neither is specified, the default for the model will be used.
50+
/// </param>
51+
/// <returns>A <see cref="IChatClient"/> instance representing the <see cref="IAmazonBedrockRuntime"/> instance.</returns>
52+
/// <exception cref="ArgumentNullException"><paramref name="runtime"/> is <see langword="null"/>.</exception>
53+
public static IEmbeddingGenerator<string, Embedding<float>> AsEmbeddingGenerator(
54+
this IAmazonBedrockRuntime runtime, string? modelId = null, int? dimensions = null) =>
55+
runtime is not null ? new BedrockEmbeddingGenerator(runtime, modelId, dimensions) :
56+
throw new ArgumentNullException(nameof(runtime));
57+
}

0 commit comments

Comments
 (0)