Selecting a foundation model

Introduction to Amazon Bedrock

Nikhil Rangarajan

Data Scientist

Enabling model access in Amazon Bedrock

  • Access model settings - no need to enable models for the course

A screenshot showing the Claude and Nova models enabled on the AWS Console.

Introduction to Amazon Bedrock

Lightweight vs. advanced foundation models

  • Lightweight models
    • Best for: Q&A, summarization
    • Quick response times and cost-effective
    • Example: Nova Micro, Claude Haiku

Logo of Amazon.

  • Advanced models
    • Best for: Complex reasoning, analysis
    • Comprehensive analysis capabilities
    • Example: Nova Plus, Claude Sonnet

Logo of Anthropic.

Introduction to Amazon Bedrock

Other foundation models in Amazon Bedrock

Other models available in Amazon Bedrock:

  • Meta's Llama

    • 📝 Open-source LLM for general text tasks
  • Stability AI's Stable Diffusion

    • 🖼 Specialized for image generation
  • AI21's Jurassic

    • 📈 Text generation and analysis

Meta's llama logo.

Introduction to Amazon Bedrock

Invoking Bedrock models

  • Basic structure:
import json
bedrock = boto3.client('bedrock-runtime', region_name='us-east-1')
response = bedrock.invoke_model(modelId='amazon.nova-lite-v1:0',

body=json.dumps(input_dictionary)
)
  • Returns model's response in JSON format
Introduction to Amazon Bedrock

Invoking Claude

  • Anthropic Claude
response = bedrock.invoke_model(
    modelId='anthropic.claude-3-5-sonnet-v2:0',
    body=json.dumps(

{"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 100,
"messages": [{ "role": "user", "content": [{"type": "text", "text": "your prompt here"}], }],
}
))
Introduction to Amazon Bedrock

Invoking Nova

  • Amazon Nova
response = bedrock.invoke_model(
    modelId='amazon.nova-lite-v1:0', 
    body=json.dumps(

{"messages":
[{"role": "user", "content": [{"text": "your prompt here"}] }]
}
))
Introduction to Amazon Bedrock

Extracting model response

  • Read the body of the API response
  • Convert from JSON to a Python dictionary
  • Extract output using keys
print("Claude:",

json.loads( claude_response['body'].read() )
["content"][0]["text"]
)
Hello! It's nice to meet you. How can I assist you today?
Introduction to Amazon Bedrock

Extracting model response

  • Read the body of the API response
  • Convert from JSON to a Python dictionary
  • Extract output using keys
print("Nova:",

json.loads( nova_response.get("body").read().decode() )
["output"]["message"]["content"][0]["text"]
)
Hello! How can I assist you today?
Introduction to Amazon Bedrock

Let's practice!

Introduction to Amazon Bedrock

Preparing Video For Download...