Skip to content

This Guidance shows how to unlock instant insights with a generative AI assistant that transforms content consumption across diverse sources, including web documents, PDFs, media files, and YouTube videos.

License

Notifications You must be signed in to change notification settings

aws-solutions-library-samples/guidance-for-generative-ai-assistant-on-aws

Guidance for building generative AI assistant on AWS.

Table of Contents

  1. Overview
  2. Prerequisites
  3. Deployment Steps
  4. Deployment Validation
  5. Running the Guidance
  6. Next Steps
  7. Cleanup

Overview

This GenAI assistant is designed to provide a wide range of functionalities to enhance your productivity and knowledge acquisition. It can summarize web pages to give you concise overviews of lengthy articles or reports, saving you time and effort. It offers pdf document insights by extracting key information and providing summaries, making it easier to understand complex documents. The assistant can perform information lookup to fetch relevant data on various topics, helping you find the information you need quickly. Additionally, it provides advice based on your queries, offering guidance on a variety of subjects. For those needing assistance with different languages, it offers language translation services to communicate across linguistic barriers. Overall, this GenAI assistant is a versatile tool to support your research, learning, and communication needs.

Architecture

Architecture

How It Works

  • When user first access to this GenAI Assistant application, they required to create login using valid email address.
  • Amazon Cognito create and manage user profiles.
  • User interact with application (GenAI Assistant) for chat assistance and/or summarization of web documents, PDFs etc.
  • At start a user submit messages using front-end application. These user messages can optionally include PDF files.
  • User have choice to select Amazon Bedrock Model - Amazon Nova Micro or Anthropic Claude. By default, this application uses Amazon Nova Micro model.
  • User messages are sent to Amazon Lambda function via Amazon API Gateway.
  • Amazon Lambda does the backend processing of user input. It analyze the user query and accordingly pull chat history from Amazon DynamoDB table.
  • A LLM chain is created with user chat history and new message. This LLM chain is then submitted to Amazon Bedrock for response generation.
  • Response from Amazon Bedrock is sent back to user and new history is created including the response generated by LLM.
  • A chat history is maintained per user. Users have option to select their chat histories and delete any of them.

Cost

You are responsible for the cost of the AWS services used while running this Guidance. We recommend creating a Budget through AWS Cost Explorer to help manage costs. Prices are subject to change. For full details, refer to the pricing webpage for each AWS service used in this Guidance.

Pricing

Usage scenario:

  • 10 users
  • Each user uses 10,000 tokens per day
  • Here is monthly cost breakdown for 30 days of usage
AWS Service Assumptions Calculation Estimated Monthly Cost (USD)
Amazon Bedrock (AI) 10 users × 10,000 input tokens/day, equal output tokens Input: (3,000,000 ÷ 1,000) × 0.003 = 9.00 Output: (3,000,000 ÷ 1,000) × 0.015 = 45.00 9.00 + 45.00 = 54.00
AWS Amplify 5 GB data storage, 10 GB data transfer out per month Storage: 5 × 0.023 = 0.115 Data transfer: 10 × 0.15 = 1.50
Amazon Cognito 10 monthly active users (free tier) Free tier for MAUs up to 10,000 0.00
API Gateway 10 users × 1,000 API requests/day (300,000 ÷ 1,000,000) × 3.50 = 1.05 1.05
Lambda 300,000 requests/month, no GB-second cost included (300,000 ÷ 1,000,000) × 0.20 = 0.06 0.06
DynamoDB 5 GB storage (within free tier), 1M writes, 2M reads Writes: 1 × 0.625 = 0.625 Reads: 2 × 0.125 = 0.25 0.625 + 0.25 = 0.88
Total Estimated Cost 54.00 + 1.62 + 0.00 + 1.05 + 0.06 + 0.88 57.61

Refer for current pricing:

Prerequisites

Python 3.9 or greater

AWS account requirements

  • You must have AWS account to deploy this solution.
  • Amazon Simple Storage Service(S3) bucket to stage Lambda function files and Amazon CloudFormation stack.
  • In your AWS account, select your AWS Region and request access for Foundational Models Amazon Nova Micro and anthropic.claude-3.5-sonnet on Amazon Bedrock.

Amazon Bedrock Amazon Bedrock Amazon Bedrock Amazon Bedrock

Deployment Steps

  1. You have option to host front-end of this solution locally or on AWS Amplify. AWS Amplify Hosting enables a fully-managed deployment of the application's React frontend in an AWS-managed account using Amazon S3 and Amazon CloudFront. You can choose this option during Amazon CloudFormation stack deployment.

    Follow below two steps only to set up Amplify Hosting:

  2. Download Amazon Lambda function and Amazon Lambda dependencies and upload to your Amazon S3 bucket in same AWS Region where you will deploy this solution.

  3. Download AWS CloudFormation template guidance-for-genai-assistant.yaml from the GitHub repository to your local system. Update your Amazon S3 bucket name for Amazon Lambda function code and Lambda Layer.

    S3Bucket: <YOUR AMAZON S3 BUCKET NAME> 
  4. Deploy updated CloudFormation template to deploy the solution.

Amazon CloudFormation Output

Deployment Validation

  1. Open CloudFormation console and verify the status of the CloudFormation stack. It should have CREATE_COMPLETE status.

  2. Navigate to output tab and review deployed resources

Amazon CloudFormation Output

  1. If you selected to deploy the frontend using Amazon Amplify Hosting, navigate to the Amplify console to check the build status.

Amazon Amplify App

If the build does not start automatically, trigger it through the Amplify console.

Amazon Amplify RunJob

  1. Validate environment variables setup for the Amplify App hosting

Amazon Amplify Environment Variables

  1. If you selected to run the frontend locally and connect to the deployed resources in AWS, use the CloudFormation stack outputs to verify deployed resources.

Running the Guidance

Running with Amazon Amplify hosting

  1. In the AWS Console, navigate to Amazon CloudFormation and select CloudFormation stack deployed as part of this guidance. Navigate to 'output' tab. Amazon CloudFormation Output

  2. Click on Amplify App URL to access the deployed solution. For the first time user, switch to 'Create Account' tab and follow the instructions to create new user account. Amazon Amplify Hosting

  3. After successful login, you will be presented to the main page of GenAI Assistant. Amazon Amplify Hosting

Running locally

  1. Clone this repository to your local machine where you will run the solution:
git clone https://github.com/aws-samples/guidance-for-genai-assistant.git
  1. Navigate to the solution directory
cd guidance-for-genai-assistant
  1. Create a file named .env. Vite will use this file to set up environment variables when we run the application locally.

Copy the following file content and replace the values with the outputs provided in AWS CloudFormation deployment:

VITE_IDENTITY_POOL_ID="us-east-1:xxxx"
VITE_AWS_REGION="us-east-1"
VITE_USER_POOL_ID="us-east-1_xxxx"
VITE_USER_POOL_CLIENT_ID="xxxxxx"
VITE_API_GATEWAY_ENDPOINT="https://xxxx.execute-api.us-east-1.amazonaws.com/dev/dev"
  1. Next, install the dependencies by running the following command:
npm ci
  1. Finally, to start the application locally, run the following command:
npm run dev

Vite will now start the application under http://localhost:8080. You can modify the port by updating Vite configuration file.

Next Steps

In this guide we are using Amazon Bedrock with foundational models Amazon Nova Micro and Anthropic Claude 3.5 Sonnet. You can build on top of this solution and make it more customized for your requirements. Also try other models available on Amazon Bedrock and review AWS solution library for more focused solutions.

Cleanup

When no longer needed, you can delete the resources manually or by deleting the entire AWS CloudFormation stack.

  • If you want to delete the entire stack using the CloudFormation console:

    • Sign in to the AWS CloudFormation console
    • Select the Stack GenAI-Assistant and click on delete.
  • Delete Amazon Lambda files uploaded on your Amazon S3 bucket.

Notices

Customers are responsible for making their own independent assessment of the information in this Guidance. This Guidance: (a) is for informational purposes only, (b) represents AWS current product offerings and practices, which are subject to change without notice, and (c) does not create any commitments or assurances from AWS and its affiliates, suppliers or licensors. AWS products or services are provided “as is” without warranties, representations, or conditions of any kind, whether express or implied. AWS responsibilities and liabilities to its customers are controlled by AWS agreements, and this Guidance is not part of, nor does it modify, any agreement between AWS and its customers._

License

This library is licensed under the MIT-0 License. See the LICENSE file.

Author

  • Ravi Mathur

Contribution

This repository is intended for educational purposes and does not accept further contributions. Feel free to utilize and enhance the app based on your own requirements.

About

This Guidance shows how to unlock instant insights with a generative AI assistant that transforms content consumption across diverse sources, including web documents, PDFs, media files, and YouTube videos.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •