This repository is meant as an accompaniment to the blogpost Exploring Generative AI in conversational experiences: An Introduction with Amazon Lex, Langchain, and SageMaker Jumpstart illustrating a sample integration with AWS Lambda, Amazon Lex, an out of the box LLM from Sagemaker Jumpstart, and Langchain
The /src/bot_dispatcher
directory has the code for the AWS Lambda Function used to fulfill requests from either the QnABot or the Amazon Lex V2 Bot that will communicate with the LLM hosted in Sagemaker.
Directory structure is as follows
├── __init__.py
├── dispatchers
│ ├── LexV2SMLangchainDispatcher.py
│ ├── QnABotSMLangchainDispatcher.py
│ ├── __init__.py
│ └── utils.py
├── lex_langchain_hook_function.py
├── requirements.txt
└── sm_utils
├── __init__.py
└── sm_langchain_sample.py
Comments in the code can be seen for further details.
cd
into the src
directory and run the following to build the Docker Image.
docker build -t lambda-build-langchain .
Once the Image is built, run a container from it. It will use the /src/build_langchain_layer.sh
script to create a virtual environment, install Langchain and it's dependencies, and zip it into the required format for an AWS Lambda Layer.
docker run --platform linux/amd64 \
-v "$PWD"/..:/conversational-ai-llms-with-amazon-lex-and-sagemaker \
-it lambda-build-langchain
Once it is complete, you will have a new zip file named /src/bot_disptacher/langchain_layer.zip
which can be used as an AWS Lambda Layer for Langchain.
The deploy.sh
script at the root of the directory can be used to deploy these resources into your own AWS account,
deploy.sh
script, in lines 3 and 4, change the parameters to indicate the name of your profile and the S3 bucket where you are looking to host the assetscd ..
to ensure your terminal is where the deploy.sh
script is../deploy.sh
deploy.sh
script in line 13SMJumpstartFlanT5-llm-main
template corresponding to the region where you want to deploy. It will be located in the artifacts/ML-12016/v1/stacks/
prefix. Click into it and copy the S3 URL to use as cloudformation input.
SMJumpstartFlanT5-llm-main.yaml
template SMJumpstartFlanT5-llm-main-uswest2.yaml
templateS3BucketName
parameter if you are deploying using the insturctions here. By default it will refer to the public assets accomanying the blogpost.