Skip to content

aws-samples/bedrock-genai-workshop

GenAI With Amazon Bedrock

This hands-on workshop, aimed at developers and solution builders, introduces how to leverage foundation models (FMs) through Amazon Bedrock. Amazon Bedrock is a fully managed service that provides access to FMs from third-party providers and Amazon; available via an API. With Bedrock, you can choose from a variety of models to find the one that’s best suited for your use case.

Within this series of labs, you'll explore some of the most common usage patterns we are seeing with our customers for Generative AI. We will show techniques for creating value for organizations by improving productivity. This is achieved

Labs include:

  • Text Generation [Estimated time to complete - 35 mins]
  • Text Summarization [Estimated time to complete - 20 mins]
  • Questions Answering [Estimated time to complete - 30 mins]
  • Chatbot [Estimated time to complete - 60 mins]
  • Agent [Estimated time to complete - 60 mins]

Getting started

Choose a notebook environment

This workshop is presented as a series of Python notebooks, which you can run from the environment of your choice:

Enable AWS IAM permissions for Bedrock

The AWS identity you assume from your notebook environment (which is the Studio/notebook Execution Role from SageMaker, or could be a role or IAM User for self-managed notebooks), must have sufficient AWS IAM permissions to call the Amazon Bedrock service.

To grant Bedrock and other permissions relevant for this workshop to your identity, you can:

  • Open the AWS IAM Console
  • Find your Role (if using SageMaker or otherwise assuming an IAM Role), or else User
  • Select Add Permissions > Create Inline Policy to attach new inline permissions, open the JSON editor and paste in the below example policy:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": ["bedrock:*"],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": ["iam:*"],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": ["cloudformation:*"],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": ["aoss:*"],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": ["lambda:*"],
            "Resource": "*"
        }
    ]
}

⚠️ Note: With Amazon SageMaker, your notebook execution role will typically be separate from the user or role that you log in to the AWS Console with. If you'd like to explore the AWS Console for Amazon Bedrock, you'll need to grant permissions to your Console user/role too.

For more information on the fine-grained action and resource permissions in Bedrock, check out the Bedrock Developer Guide.

Clone and use the notebooks

Amazon SageMaker Studio is the latest web-based experience for running ML workflows. Studio offers a suite of IDEs, including Code Editor, based on Code-OSS, Visual Studio Code - Open Source, a new JupyterLab application, RStudio, and Amazon SageMaker Studio Classic. For more information about the applications supported in Studio, see Applications supported in Amazon SageMaker Studio.

Given most of the lab contents are developed in juypter notebooks, we'll be using a Jupyterlab app within SageMaker Studio.

Launching a SageMaker Studio session

  1. From Amazon SageMaker console, navigate to "Domains" in the left panel.
  2. Select the SageMaker Domain created for this workshop
  3. Under User Profile tab, Idenfity the user assigned to you. Click the "Launch" drop down and select "Studio"

sm-studio-launch

  1. In the SageMaker Studio launcher, select "JupterLab" icon from the top left pane as shown below:

sm-studio-app-launch

  1. Click on "**Create JupyterLab Space" button on the top right corner:

jl-space

  1. Provide a name for the JupyterLab space, and select "Create space"

  2. Configure Instance: ml.t3.medium, Image: SageMaker Distribution 1.2, Storage: 50 (GB), then click "Run space"

jl-space-run

ℹ️ Note: In JupyterLab, you can open a "System Terminal" to run these commands by clicking File > New > Terminal

Once your notebook environment is set up, clone this workshop repository into it.

sudo apt update && sudo apt install -y unzip zip
git clone https://github.com/aws-samples/bedrock-genai-workshop.git
cd bedrock-genai-workshop

Content

This repository contains notebook examples for the Bedrock Architecture Patterns workshop. The notebooks are organised by module as follows:

Intro

  • Simple Bedrock Usage: This notebook shows setting up the boto3 client and some basic usage of bedrock.

Generation

Summarization

  • Small text summarization: In this notebook, you use use Bedrock to perform a simple task of summarizing a small piece of text.
  • Long text summarization: The above approach may not work as the content to be summarized gets larger and exceeds the max tokens of the model. In this notebook we show an approach of breaking the file up into smaller chunks, summarizing each chunk, and then summarizing the summaries.

Question Answering

  • Simple questions with context: This notebook shows a simple example answering a question with given context by calling the model directly.
  • Answering questions with Retrieval Augmented Generation: We can improve the above process by implementing an architecure called Retreival Augmented Generation (RAG). RAG retrieves data from outside the language model (non-parametric) and augments the prompts by adding the relevant retrieved data in context.

Chatbot

Agent

  • This lab shows how you could build an LLM Agent using Agent for Amazon Bedrock.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published