IniziaInizia gratis

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".

Questo esercizio fa parte del corso

Introduction to Amazon Bedrock

Visualizza il corso

Istruzioni dell'esercizio

  • Set the keys in the dictionary to complete the "messages" list for the Nova model.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

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"])
Modifica ed esegui il codice