始める無料で始める

商品レビューに関する Few-shot プロンプト

あなたは、BrightCart という EC プラットフォームで働いています。商品ページには、数千件の顧客レビューを簡潔なインサイトにまとめる、"Quick-Read" AI が追加されました。このインサイトをさらに分かりやすくするために、あなたは要約を 2 つの文に分割しようと考えています。1 つ目の文は商品が優れている点について、2 つ目は率直な懸念点を表示します。

Few-shot プロンプトを使ってこの形式を Claude に教え、今後すべての商品で同じバランスの取れた要約が生成されるようにしましょう。

anthropicライブラリ、client、およびサンプルのraw_reviewはあらかじめ読み込まれています。

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

Claude モデル入門

コースを見る

演習の手順

  • 最初の応答例で、Claude に正しい役割を設定します。
  • 商品について 2 つの文で構成される要約を書くように指示します。
  • API に全ての messages 配列を渡します。

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

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

messages = [
    {"role": "user", "content": "Summarize: Nice phone, fast performance, great camera. Screen scratches easily though."},
    # Set the role for Claude's first example response
    {"role": ____, "content": "Fast performance and excellent camera make this phone stand out. However, the screen may be prone to scratching."},
    {"role": "user", "content": "Summarize: Comfortable shoes, good for walking. Run small, order size up."},
    # Write a 2-sentence summary following the established pattern
    {"role": "assistant", "content": ____},
    {"role": "user", "content": f"Summarize: {raw_review}"}]

# Pass the complete messages array to the API call
response = client.messages.create(
    model="claude-sonnet-4-6", max_tokens=75,
    messages=____)

print(response.content[0].text)
コードを編集して実行