|
1 | 1 | # Build a generative AI Virtual Assistant with [Amazon Bedrock](https://aws.amazon.com/bedrock/), [Langchain](https://github.com/langchain-ai/langchain) and [Amazon Elasticache](https://aws.amazon.com/elasticache/) |
2 | 2 |
|
3 | | -In this 15-minute session [YouTube video](https://www.youtube.com/watch?v=yWxDmQYelvg), we will discuss how you can use [Amazon Bedrock](https://aws.amazon.com/bedrock/), [Langchain](https://github.com/langchain-ai/langchain) and [Amazon Elasticache](https://aws.amazon.com/elasticache/) services together to implement a generative AI (GenAI) chatbot. We will dive into two application patterns: they are chat history and messaging broker patterns. We will show you how ElastiCache for Redis simplifies the implementation of these application patterns by leveraging the built-in Redis data structures. |
4 | | - |
5 | | -ElastiCache is a fully managed, Redis- and Memcached-compatible service delivering real-time, cost-optimized performance for modern applications. |
| 3 | +In this 15-minute session [YouTube video](https://www.youtube.com/watch?v=yWxDmQYelvg), we will discuss how you can use [Amazon Bedrock](https://aws.amazon.com/bedrock/), [Langchain](https://github.com/langchain-ai/langchain) and [Amazon Elasticache](https://aws.amazon.com/elasticache/) services together to implement a generative AI (GenAI) chatbot. We will dive into two application patterns: they are chat history and messaging broker patterns. We will show you how ElastiCache simplifies the implementation of these application patterns by leveraging the built-in Redis data structures. |
6 | 4 |
|
| 5 | +ElastiCache is a fully managed service delivering real-time, cost-optimized performance for modern applications. |
7 | 6 | ElastiCache scales to hundreds of millions operations per second with microsecond response time, and offers enterprise-grade security and reliability. |
8 | | - |
9 | 7 | ## Chatbot Application Deployment |
10 | 8 |
|
11 | 9 | This guide will walk you through the steps to deploy a Python chatbot application using [Streamlit](https://github.com/streamlit/streamlit) on [Cloud9](https://aws.amazon.com/cloud9/). This is the architecture we will be implementing today. |
12 | 10 |
|
| 11 | + |
13 | 12 |  |
14 | 13 |
|
15 | | -The application is contained in the `chatbot_app.py` file, and it requires specific packages listed in `requirements.txt`. |
| 14 | + |
| 15 | +The application is contained in the 'chatbot_app.py' file, and it requires specific packages listed in 'requirements.txt'. |
16 | 16 |
|
17 | 17 | ## Prerequisites |
18 | 18 |
|
| 19 | + |
19 | 20 | Before you proceed, make sure you have the following prerequisites in place: |
20 | 21 |
|
21 | 22 | 1. An AWS Cloud9 development environment set up. |
| 23 | + |
22 | 24 | 2. We will be using [Amazon Bedrock](https://aws.amazon.com/bedrock/) to access foundation models in this workshop. |
23 | | -3. Enable Foundation models such as Claude, as shown below: |
24 | 25 |
|
| 26 | +3. Enable Foundation models such as Claude, as shown below: |
25 | 27 |  |
26 | 28 |
|
27 | 29 | 4. Python and pip installed in your Cloud9 environment. |
28 | | -5. Internet connectivity to download packages. |
29 | 30 |
|
30 | | -## Installation |
31 | 31 |
|
| 32 | +## Installation |
32 | 33 | 1. Clone this repository to your Cloud9 environment: |
33 | 34 |
|
34 | 35 | ```bash |
35 | | -git clone [your-repo-url] |
36 | | -cd chatbot-app |
| 36 | +git clone https://github.com/aws-samples/amazon-elasticache-samples.git |
| 37 | +``` |
| 38 | + |
| 39 | +``` |
| 40 | +cd webinars/genai-chatbot |
37 | 41 | ``` |
38 | | - |
| 42 | + |
39 | 43 | 2. Install the required packages using pip: |
40 | 44 |
|
41 | 45 | ```bash |
42 | | -pip3 install -r ~/environment/workshop/setup/requirements.txt -U |
| 46 | +pip3 install -r ~/environment/workshop/setup/requirements.txt -U |
43 | 47 | ``` |
44 | 48 |
|
45 | | -3. Configure environment variables. |
| 49 | +3. Set the ElastiCache cluster endpoint as below. Use redis instead of rediss it encryption is not enabled. |
46 | 50 |
|
| 51 | +```bash |
| 52 | +export ELASTICACHE_ENDPOINT_URL=rediss://ClusterURL:6379 |
| 53 | +``` |
47 | 54 |
|
48 | | -4. You can run the following commands to confirm: |
49 | | -(check [Amazon Bedrock endpoints and quotas](https://docs.aws.amazon.com/general/latest/gr/bedrock.html)) |
| 55 | +## Running the Application |
50 | 56 |
|
51 | 57 | ```bash |
52 | | -echo $BWB_ENDPOINT_URL |
53 | | -echo $BWB_PROFILE_NAME |
54 | | -echo $BWB_REGION_NAME |
| 58 | +streamlit run 'chatbot_app.py' --server.port 8080 |
55 | 59 | ``` |
56 | 60 |
|
| 61 | +## Testing the chat history with ElastiCache |
57 | 62 |
|
58 | | -## Running the Application |
| 63 | +The first step is to login to the application. This would create a unique session to be stored in Amazon ElastiCache. This session data is retrieved, summarized and provided as a context to the LLM to help stay in context. |
| 64 | + |
| 65 | + |
59 | 66 |
|
| 67 | +Here are some sample questions you can try out to validate the LLM stays in context while loading previous conversation from Elasticache. |
| 68 | + |
| 69 | + 1. Can you help me draft a 4 sentence email to highlight some fun upcoming events for my employees? |
| 70 | + |
| 71 | + 2. Can you add in these events into the email: 1. Internal networking event on 4/20/2024, Summer gift giveaway on 6/20/2024, 3. End of summer picnic: 8/15/2024, 4. Fall Formal on 10/10/2024, and 5. Christmas Party on 12/18/2024 |
| 72 | + |
| 73 | + 3. Can you reformat it with bullets for my events? |
| 74 | + |
| 75 | + 4. Can you please remove everything that happens after September 2024 |
| 76 | + |
| 77 | +Here is how we can check the session data stored in ElastiCache. |
60 | 78 | ```bash |
61 | | -streamlit run chatbot_app.py --server.port 8080 |
62 | | -``` |
| 79 | +redis-cli -c --user $ECUserName --askpass -h $ELASTICACHE_ENDPOINT_UR --tls |
| 80 | + |
| 81 | +``` |
63 | 82 |
|
| 83 | +``` |
| 84 | +LRANGE "chat_history:user1" 0 -1 |
| 85 | +``` |
0 commit comments