This repository is intended to provide sample code on how to execute/call AWS Bedrock with either the AWS SDK v3 or using langchain.
The samples are mostly self-contained and can be executed independently, readers should ensure to:
- Have AWS Bedrock & the Claude Instant v1 model enabled on their accounts
- Have the AWS credentials configured on their terminals
- Have Node JS installed
- Execute
npm i
to install the dependencies - Replace the required variables with the correct information
- Run the desired sample with
node <sample-file-name>.js
Note
Langchain examples that contain the word memory
in the file name also require a DynamoDB table to be created. review the Official Documentation for further details on how this is expected to work.
The Bedrock Agent Example also requires the user to have configured a AWS Bedrock agent on their account beforehand.
Following is a list of the currently available provided samples.
- Basic Example: Sample of executing a single synchronous call to AWS Bedrock.
- Streamed Response: Improvement of the first example to allow for receiving streamed responses from Bedrock.
- Bedrock Agent: Sample code on how to trigger the execution of an existing Bedrock Agent.
- Basic Example: Sample of executing a single synchronous call to AWS Bedrock using the Langchain framework.
- Streamed Response: Example code to get a streamed response from Bedrock when executing it with Langchain.
- Conversation Chain + Memory: Sample of how to configure Langchain to use a Conversation Chain and store the Conversation History on a DynamoDB table
- Conversation Chain + Memory + Streamed Response: Improved the previous sample to also return the Bedrock response as a stream.