GenAI Powered Chatbot Using Bedrock and Lex
Dinesh Sharma
Mentor | AWS Ambassador | Puluminary | AWS Community Builder | AWS Regional Practice Lead | IaC Ninja | Desi | PB13 | RJ19
Ever wondered how to build your own AI-powered chatbot without diving deep into the complexities of machine learning? Well, you're in luck! Today, we'll craft a chatbot for booking a adventurous trip to Jurassic Park. Yes, you read that right! And we’ll do this using Amazon Bedrock and Lex in just 15 minutes. Let's get started, fellow tech adventurers!
Step 1: Enable Your Models in Amazon Bedrock
Before we bring our Bot to life, make sure to enable the following models on Amazon Bedrock:
For those, who are new to Bedrock, search for Bedrock in the services. Once, in there, please navigate to Bedrock configurations and click on Model access.
Look for one of the model like Titan Embeddings G1 - Text. Click on the option "Available to request", it will open a small pop up window, click on the link "Request model access"
Access the model activation interface in your Amazon Bedrock console. Here, you'll find options to enable various models. Select "Titan Embeddings G1 - Text", "Claude", and "Claude 2.1" from the available list of models.
Click on the 'Next' button to proceed. If this is your first time activating models, you will be prompted to enter your company details. For testing purposes, you can enter placeholder information in these fields.
After entering your details, click the 'Submit' button to finalize the setup. It may take up to five minutes for the models to become fully active. This is a normal part of the process as the system configures and enables the selected models.
Once the models are enabled, you will see them listed in your console's model management section, indicating that they are ready for use.
Step 2: Create Your Knowledge Base
Our chatbot needs brains, and what better brains than a knowledge base built directly from Jurassic Park's own guides? Here’s how:
The files mentioned above will act as the Knowledge Base documents, please clone/copy the files.
Click on Create dropdown and select the option of Knowledge Base with Vector Store
Select the option to create a new IAM role and choose an S3 bucket as the data source. Click 'Next' to proceed to the following page, where you should click on 'Browse S3' and select the S3 bucket where the files have been uploaded.
Next, it will take you embeddings selection model page, select Titan Embeddings G1 - Text v1.2 and Vector Database option as default.
Next, click to Create the Knowledge Base, it may take few minutes to create the Knowledge base.
Once, the sync is completed, you should be able to see 5 files under Source files, as we copied 5 files in the S3 bucket.
So, by now we have the knowledge base successfully created.
Step 3: Crafting the Chatbot with Amazon Lex
Now, onto the fun part—building our chatbot, affectionately named JurassicParkBookingBot.
Create the Bot:
领英推荐
Create the Intents:
Next we need to create the intents. Although we can design multiple intents based on the chatbot’s requirements, let’s keep it simple for this use case. We will create two intents: a simple greetings intent and a general inquiry or Question and Answer intent that will link to the Knowledge Base we have created.
1. GreetingIntent:
So, as you can see, the chatbot at the moment has no idea about the Jurassic Park Knowledge Base we created. Hence, it FallBackIntent kicked in which is a default intent.
2. GeneralInquiryIntent:
Testing the Bot
Alright, we've hit an interesting part of our setup! We’ve got our Knowledge Base in place, supported by documents in an S3 bucket. Alongside that, we've crafted a Lex chatbot equipped with two main intents. Initially, our chatbot featured just the greetings intent, and during our early tests, it didn’t manage to handle queries about Jurassic Park. Now, with our second AI-powered intent that taps into the Knowledge Base, it’s time to see how it performs with these queries. Let’s run some tests and check out the responses!
With the integration of the Knowledge Base, the chatbot has started responding to all related queries. Now that the AI-powered intent is functioning with the support of the Knowledge Base, you'll find that the bot handles questions about Jurassic Park much more effectively. Feel free to test it further with a variety of queries based on the information in the documents to see how it adapts and responds.
Cleanup the resources
Once you've finished testing your chatbot and want to ensure that you're not billed further, here are the key AWS resources you should consider deleting or terminating:
This wraps up our blog for today, I hope this demonstration has been helpful and inspires you to explore further what you can achieve with AI-powered chatbots. Happy experimenting!