Generating text in Bedrock
Building on your success with Claude, the specialty-coffee company now wants to roll out AI-assisted writing to their marketing department. They're launching a New Year campaign and need compelling subject lines: it's time to generate some catchy options with Bedrock!
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".
Latihan ini adalah bagian dari kursus
Introduction to Amazon Bedrock
Petunjuk latihan
- Set the keys in the dictionary to complete the
"messages"list for the Nova model.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
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"])