Few shot prompting for product reviews
You work for BrightCart, an e-commerce platform. Product pages are now showing an AI “Quick-Read” badge that condenses thousands of customer reviews into bite-sized insights. To simplify the insights even further, you'll be splitting summaries into two sentences: a the standout positive takeaway as the first one, and one honest concern as the second.
Teach Claude that exact format via few-shot prompting so every future product gets the same balanced summary.
The anthropic library, client, and a raw_review sample are pre-loaded.
Diese Übung ist Teil des Kurses
Introduction to Claude Models
Anleitung zur Übung
- Set the correct role for Claude's first example response.
- Ask to write a 2-sentence summary about the product.
- Pass the complete messagesarray to the API call.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
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-3-7-sonnet-latest", max_tokens=75,
    messages=____)
print(response.content[0].text)