Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Per issue #87
Description
Added a connector class and initial set of endpoint configuration JSONs for connecting to foundation models on Amazon Bedrock.
Motivation and Context
Bedrock is AWS' pay-as-you-go service for consuming foundation models from a range of popular providers: Including AI21, Amazon themselves, Anthropic, Cohere, Meta, Mistral, and Stability AI. This PR should enable AWS customers to use Moonshot to test models they're consuming through Bedrock.
Type of Change
feat: A new feature
How to Test
[Provide clear instructions on how to test and verify the changes introduced by this pull request, including any specific unit tests you have created to demonstrate your changes.]
Checklist
Please check all the boxes that apply to this pull request using "x":
boto3
was already implicitly installed byrequirements.txt
but is now also an explicit dependency inpyproject.toml
. Is anything else needed on e.g. the CI side?Screenshots (if applicable)
N/A - no visual changes
Additional Notes
AWS API Authentication & Endpoints
Programmatic authentication to AWS APIs is a bit different from the basic API key pattern that Moonshot generally expects, and some specific suggested best-practices include avoiding storing API keys in code or files where possible.
Typical recommended practice (as documented in the connector file docstring) would be to configure the credentials via whatever environment you run Moonshot on: For example as per the CLI for running locally, or just by setting permissions on your execution role if deploying Moonshot to an AWS EC2 instance or ECS/EKS container, etc.
Since the API token field currently seems to be mandatory in Moonshot, this connector explicitly ignores short, placeholder-looking tokens and users are encouraged not to use the token configuration. However, it will try to pass longer-looking tokens through as an AWS_SESSION_TOKEN if provided.
Likewise, AWS users aren't typically expected to look up the exact endpoint URLs of the various services they use - because the SDK takes care of that in most cases.
As follow-up to this PR, I would actually suggest we start a discussion on the main Moonshot repo for:
Wrapping synchronous SDK with asyncio.to_thread
AWS' official SDK for Python, boto3, is synchronous by design. There is a pretty popular 3rd-party alternative, aioboto3 - but today that explicitly requires service clients to be created via
async with
context managers, which doesn't sit well with Moonshot's class-based connector initialisation design. Re-building the client on everyget_response
would likely be pretty inefficient; hacking around with__aenter__()
would risk leaking resources; and sticking with plain boto3 allowed us to not introduce any new dependencies (since boto3 was already present).As a result, this PR sticks to classic boto3 and just wraps model invocations with
asyncio.to_thread
to try and maintain appropriate concurrency.Endpoint naming
I did wonder whether to switch the naming of the example connector configurations around to e.g. "Llama 3.1 8B Instruct on Amazon Bedrock", but figured that users would probably rather see e.g. all the AWS/Bedrock-hosted models together rather than all the different hosting options for Llama together.
I notice that the current Moonshot UI doesn't scale super nicely for a large number of configured endpoints... Maybe it'd be nice to add a search box on the endpoint selection screen in future?
Developer Certificate of Origin