始める無料で始める

Temperature を使った創造性の制御

あなたはアウトドアブランド Luna Gear のプロダクトリードです。エコフレンドリーなバックパック TerraPack のローンチに向けて、A/B テスト用のキャプションを2 種類用意する必要があります。1 つは洗練された情報重視のもの、もう 1 つは遊び心と高揚感をもたらすものです。

anthropic ライブラリ、client、および product_info 文字列はあらかじめ読み込まれています。

この演習はコースの一部です

Claude モデル入門

コースを見る

演習の手順

  • 一貫性のあるプロフェッショナルな出力には、temperature を低い値(0.1〜0.3)に設定します。
  • 創造的でバリエーション豊かな出力には、temperature を高い値(0.7〜0.9)に設定します。
  • 保守的な応答と創造的な応答を出力してください。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

conservative_response = client.messages.create(
  # Conservative caption with low temperature
    model="claude-sonnet-4-6", 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-sonnet-4-6", 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:", ____)
コードを編集して実行