Module 3 Wrap-up: Your First AI Call
Hands-on: Write a script that compares the outputs of two different models using the same prompt.
Module 3 Wrap-up: The API Developer
You have graduated from the AWS Console to the Python IDE. You understand the difference between the low-level InvokeModel (Control) and the high-level Converse (Unified) APIs. You are now ready to build scalable, multi-model applications.
Hands-on Exercise: The Model Duel
1. The Goal
Create a Python script that takes a prompt and sends it to Llama 3 8B and Claude 3 Haiku using the Converse API.
2. The Implementation Plan
- Define a
promptvariable. - Write a function
call_bedrock(model_id, prompt). - Call the function twice.
- Print the results side-by-side.
3. Key Discovery
Notice how the output "Vibe" changes even though the code is identical except for the modelId.
Module 3 Summary
- Boto3: The AWS SDK for Python.
- Bedrock-Runtime: The client used for model execution.
- Converse API: The future-proof way to build text applications.
- Consistency: Unified APIs allow for rapid model switching and testing.
- Error Handling: Watching for Throttling and Validation exceptions.
Coming Up Next...
In Module 4, we focus on the "Data" we send to these APIs: Prompt Engineering. We will learn how to use System Messages and Guardrails in Bedrock to ensure our AI stays on-task and professional.
Module 3 Checklist
- I have installed
boto3. - I can explain the difference between
InvokeModelandConverse. - I have successfully run a Python script that calls a Bedrock model.
- I can find the
textcontent inside a Converse API response object. - I understand how to set
maxTokensandtemperature.