LoslegenKostenlos loslegen

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

Kurs anzeigen

Anleitung zur Übung

  • Set a low temperature value for consistent, professional output (0.1-0.3).
  • Set a high temperature value 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:", ____)
Code bearbeiten und ausführen