Get startedGet started for free

Parameters for product descriptions

You're working with Amazon Bedrock to generate product descriptions. You need to understand how different parameter settings affect the model's output. Using the provided generate_description function, you can experiment with different combinations of temperature, top_p, and max_tokens to see how they influence the style and consistency of generated product descriptions.

The boto3 and json libraries, and generate_description() function, have been pre-imported.

This exercise is part of the course

Introduction to Amazon Bedrock

View Course

Exercise instructions

  • Set parameters for three configurations, using different values of the parameters for a conservative, balanced, and creative output.

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')
product = "Wireless Noise-Cancelling Headphones"

# Configuration 1: Conservative/Consistent
result1 = generate_description(bedrock, product, temperature=____, top_p=0.85, max_tokens=50)
# Configuration 2: Balanced
result2 = generate_description(bedrock, product, temperature=0.5, top_p=0.92, max_tokens=____)
# Configuration 3: Creative
result3 = generate_description(bedrock, product, temperature=0.8, top_p=____, max_tokens=200)

print("Conservative Result:", result1)
print("Balanced Result:", result2)
print("Creative Result:", result3)
Edit and Run Code