.Net: Add Bedrock Connector
Motivation and Context
There has been a strong demand from developers in the community to be able to utilize Bedrock with the Semantic Kernel. With the wide variety of foundation models offered including specialized models tailored for various domains and use cases, Bedrock's AI capabilities can now be leveraged within the Semantic Kernel's unified ecosystem with this connector.
Description
This pull request implements a connector for Amazon Bedrock, allowing developers to leverage Bedrock's foundation models within the Semantic Kernel framework. Key features of this implementation include:
- Core Services: Implementation of
IChatCompletionServiceandITextGenerationServicefrom the Semantic Kernel. - Authentication and Security: Secure client authentication and API communication with the Amazon Bedrock Runtime.
- Modular Design: A directory organization and namespace structure similar to other connectors in the Semantic Kernel, including folders for core, services, models, and extensions.
- Testing: Inclusion of unit tests and integration tests for available Bedrock models to demonstrate successful communication with Bedrock API, request/response mapping, and output generation.
The implementation leverages the following Amazon Bedrock Runtime actions:
InvokeModelAsyncandInvokeModelWithResponseStreamAsyncforGetTextContentsAsyncandGetStreamingTextContentsAsync, respectively.ConverseAsyncandConverseStreamAsyncforGetChatMessageContentsAsyncandGetStreamingChatMessageContentsAsync, respectively.
The following base models from various providers are currently connected and available for use under Bedrock:
- AI21 Labs Jamba
- AI21 Labs Jurassic-2 series
- Amazon Titan
- Anthropic Claude
- Cohere Command
- Meta Llama 3
- Mistral AI Mistral
The kernel builder extension methods support two authentication scenarios:
- User-provided
IAmazonBedrockRuntimeobject: Developers can provide a pre-configuredIAmazonBedrockRuntimeobject, allowing for customized configurations such as specifying custom credentials, endpoints, or other settings. - Automatic
IAmazonBedrockRuntimecreation: If developers do not provide anIAmazonBedrockRuntimeobject, an instance is automatically created and registered in the dependency injection (DI) container using theAWSSDK.Extensions.NETCore.Setuppackage. In this case, theIAmazonBedrockRuntimeobject will be configured with default settings, such as credentials obtained from environment variables, AWS credentials files, or instance profile credentials.
Resolve #3094 Resolve #4335
- #3094
- #4335
Contribution Checklist
- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the SK Contribution Guidelines and the pre-submission formatting script raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone :smile:
@microsoft-github-policy-service agree company="Amazon"
On Wed, Jul 31, 2024 at 3:30 PM microsoft-github-policy-service[bot] < @.***> wrote:
@charlizeyeh https://github.com/charlizeyeh please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
@microsoft-github-policy-service agree [company="{your company}"]
Options:
- (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
- (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"
Contributor License Agreement Contribution License Agreement
This Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”), and conveys certain license rights to Microsoft Corporation and its affiliates (“Microsoft”) for Your contributions to Microsoft open source projects. This Agreement is effective as of the latest signature date below.
- Definitions. “Code” means the computer software code, whether in human-readable or machine-executable form, that is delivered by You to Microsoft under this Agreement. “Project” means any of the projects owned or managed by Microsoft and offered under a license approved by the Open Source Initiative (www.opensource.org). “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any Project, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of discussing and improving that Project, but excluding communication that is conspicuously marked or otherwise designated in writing by You as “Not a Submission.” “Submission” means the Code and any other copyrightable material Submitted by You, including any associated comments and documentation.
- Your Submission. You must agree to the terms of this Agreement before making a Submission to any Project. This Agreement covers any and all Submissions that You, now or in the future (except as described in Section 4 below), Submit to any Project.
- Originality of Work. You represent that each of Your Submissions is entirely Your original work. Should You wish to Submit materials that are not Your original work, You may Submit them separately to the Project if You (a) retain all copyright and license information that was in the materials as You received them, (b) in the description accompanying Your Submission, include the phrase “Submission containing materials of a third party:” followed by the names of the third party and any licenses or other restrictions of which You are aware, and (c) follow any other instructions in the Project’s written guidelines concerning Submissions.
- Your Employer. References to “employer” in this Agreement include Your employer or anyone else for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your Submission is made in the course of Your work for an employer or Your employer has intellectual property rights in Your Submission by contract or applicable law, You must secure permission from Your employer to make the Submission before signing this Agreement. In that case, the term “You” in this Agreement will refer to You and the employer collectively. If You change employers in the future and desire to Submit additional Submissions for the new employer, then You agree to sign a new Agreement and secure permission from the new employer before Submitting those Submissions.
- Licenses.
- Copyright License. You grant Microsoft, and those who receive the Submission directly or indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the Submission to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute the Submission and such derivative works, and to sublicense any or all of the foregoing rights to third parties.
- Patent License. You grant Microsoft, and those who receive the Submission directly or indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under Your patent claims that are necessarily infringed by the Submission or the combination of the Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and import or otherwise dispose of the Submission alone or with the Project.
- Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are granted by implication, exhaustion, estoppel or otherwise.
- Representations and Warranties. You represent that You are legally entitled to grant the above licenses. You represent that each of Your Submissions is entirely Your original work (except as You may have disclosed under Section 3). You represent that You have secured permission from Your employer to make the Submission in cases where Your Submission is made in the course of Your work for Your employer or Your employer has intellectual property rights in Your Submission by contract or applicable law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You have the necessary authority to bind the listed employer to the obligations contained in this Agreement. You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES EXPRESSLY STATED IN SECTIONS 3, 4, AND 6, THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
- Notice to Microsoft. You agree to notify Microsoft in writing of any facts or circumstances of which You later become aware that would make Your representations in this Agreement inaccurate in any respect.
- Information about Submissions. You agree that contributions to Projects and information about contributions may be maintained indefinitely and disclosed publicly, including Your name and other information that You submit with Your Submission.
- Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and the parties consent to exclusive jurisdiction and venue in the federal courts sitting in King County, Washington, unless no federal subject matter jurisdiction exists, in which case the parties consent to exclusive jurisdiction and venue in the Superior Court of King County, Washington. The parties waive all defenses of lack of personal jurisdiction and forum non-conveniens.
- Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and supersedes any and all prior agreements, understandings or communications, written or oral, between the parties relating to the subject matter hereof. This Agreement may be assigned by Microsoft.
— Reply to this email directly, view it on GitHub https://github.com/microsoft/semantic-kernel/pull/7587#issuecomment-2261566329, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZSRE4GDS3HXFZK6RFLVKT3ZPFQSFAVCNFSM6AAAAABLZLN7CSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRRGU3DMMZSHE . You are receiving this because you were mentioned.Message ID: @.***>
Please, also fix pipeline format error and and failing unit tests .
Please, also fix pipeline
formaterror and and failingunit tests.
Hopefully resolved now that I pulled this commit into our fork to fix format errors
To ensure the formatting is ok, when building the project ensure you use dotnet build -c Release this will automatically trigger the analysis/formatter.
Apologies, I think there were extra usings in execution settings classes. dotnet format should be fixed now
I still see some XmlDocs without description for params and return, suggest doing a full overview.
Search for should help:
<returns></returns>></param>
Overall LGTM
The usings I believe you will only be able to solve, removing the <ImplicitUsings>enable</ImplicitUsings> from the .csproj
@RogerBarret0 Thank you for taking the time to review and excited to have this merged! The next PR (which adds text embedding and text to image service will include the prompt execution settings naming update). One question - will this branch be merged with main and if so, are there any steps on our end for that?
@charlizeyeh, yes, all connectors feature branches as of now intend to merge in main at some point. The merging in main process goes around more series of reviews PR in the future and may arise as the team analyses it. Normally I try to do the most of this checks but another suggestions may come as part of it. From your side I just need to understand what are the missing features you plan to add prior to merging.
One feature that we want to add as part of the connectors is Function Calling/Tool Calling using our SK AutoFunctionInvocation abstractions but this is currently being finalized by @SergeyMenshykh.
@charlizeyeh thanks for your connector! I am looking forward to using it. Does it already support function calling (with Claude)?
@charlizeyeh, yes, all connectors feature branches as of now intend to merge in main at some point. The merging in main process goes around more series of reviews PR in the future and may arise as the team analyses it. Normally I try to do the most of this checks but another suggestions may come as part of it. From your side I just need to understand what are the missing features you plan to add prior to merging.
One feature that we want to add as part of the connectors is
Function Calling/Tool Callingusing our SKAutoFunctionInvocationabstractions but this is currently being finalized by @SergeyMenshykh.
@RogerBarret0 Could you please merge this PR into main which has the implementation of IChatCompletionService and ITextGenerationService. We will publish a new PR for the Function Calling/Tool Calling once the abstractions are ready. I will be contributing to the .NET Bedrock connector moving forward.
@RogerBarreto Any update on the question above? We'd love to get this out.
@Beau-Gosse-dev yes, we have plan on moving this one forward next sprint 35 (Sep-23 / Oct-06).
- #4335
Do you have models for TextEmbeddings? Would be nice to have some options for the ITextEmbeddingGenerationService interface in the connector.
@RogerBarreto Thanks for the update. There is a first draft of TextEmbeddings support in our fork, but we've been pulled into other priorities at the moment and wouldn't be able to get it fully ready before your next sprint, so hopefully the first release can go without it and we can support TextEmbeddings in a later release.