Generating text in Bedrock
In this exercise, you'll practice interacting with the Amazon Nova model in Amazon Bedrock, asking for help writing an engaging email subject line.
The boto3
and json
libraries have been pre-imported. The prompt
is already provided as: "Write an engaging email subject line for a coffee company's New Year marketing campaign"
.
This exercise is part of the course
Introduction to Amazon Bedrock
Exercise instructions
- Set the keys in the dictionary to complete the
"messages"
list for the Nova model.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
bedrock = boto3.client('bedrock-runtime', region_name='us-east-1')
# Set the dictionary keys
message = {"____": "user",
"____": [{"text": prompt}]}
nova_response = bedrock.invoke_model(modelId='amazon.nova-lite-v1:0', body=json.dumps({"messages": [message]}))
print(json.loads(nova_response.get("body").read().decode())["output"]["message"]["content"][0]["text"])