BaşlayınÜcretsiz başlayın

Processing model responses and error handling

SkyCast Assistant also powers personalized weather alerts. As part of this initiative, they've asked to generate a reply to a user who wants to change the frequency of their newsletter. Use Claude to generate the response, then parse it so the final message fits into the app’s compact notification view.

The json library, bedrock client, and request_body have been pre-imported.

Bu egzersiz, kursun bir parçasıdır

Introduction to Amazon Bedrock

Kursa Göz Atın

Egzersiz talimatları

  • Check if the 'output' key exists in the data dictionary.
  • Extract 'text' from the content in the message output.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

response = bedrock.invoke_model(modelId='us.amazon.nova-2-lite-v1:0', body=request_body)
data = json.loads(response['body'].read().decode())

# Check for the output key
if '____' in ____:
    response = data['output']['message']['content'][0]['____'][:100]
    print(response)
else:
    print('Key not found')
Kodu Düzenle ve Çalıştır