Controlling creativity with temperature
You’re the product lead at Luna Gear, launching the eco-friendly TerraPack backpack. The team needs A/B captions for a test: one polished and informative, one playful and hype-driven.
The anthropic library, client and product_info string are preloaded.
Diese Übung ist Teil des Kurses
Introduction to Claude Models
Anleitung zur Übung
- Set a low temperaturevalue for consistent, professional output (0.1-0.3).
- Set a high temperaturevalue for creative, varied output (0.7-0.9).
- Print the conservative and creative response contents.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
conservative_response = client.messages.create(
  # Conservative caption with low temperature
    model="claude-3-7-sonnet-latest", temperature=____, max_tokens=150,
    messages=[{"role": "user", 
        "content": f"Write a professional caption for this product: {product_info}"}])
creative_response = client.messages.create(
  # Creative caption with high temperature  
    model="claude-3-7-sonnet-latest", temperature=____, max_tokens=150,
    messages=[{"role": "user",
        "content": f"Write a fun, engaging caption for this product: {product_info}"}])
# Print the Conservative and Creative Responses
print("Conservative caption:", ____)
print("\nCreative caption:", ____)