เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Few-shot Prompting สำหรับรีวิวสินค้า

คุณทำงานให้กับ BrightCart แพลตฟอร์มอีคอมเมิร์ซแห่งหนึ่ง หน้าสินค้าตอนนี้แสดงตรา AI "Quick-Read" ที่สรุปรีวิวจากลูกค้าหลายพันรายการให้กระชับและอ่านง่าย เพื่อให้สรุปใจความนั้นกระชับยิ่งขึ้น จึงแบ่งออกเป็น 2 ประโยค ได้แก่ จุดเด่นที่โดดเด่นที่สุดเป็นประโยคแรก และข้อกังวลที่ควรทราบเป็นประโยคที่สอง

สอน Claude ให้ใช้รูปแบบนี้ผ่าน few-shot prompting เพื่อให้สินค้าทุกชิ้นได้รับสรุปที่สมดุลในแบบเดียวกัน

ไลบรารี anthropic, client และตัวอย่าง raw_review ถูกโหลดไว้ให้แล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Claude Models เบื้องต้น

ดูคอร์ส

คำแนะนำการฝึกหัด

  • กำหนด role ที่ถูกต้องสำหรับตัวอย่างการตอบกลับแรกของ Claude
  • ขอให้เขียนสรุป 2 ประโยคเกี่ยวกับสินค้า
  • ส่ง array messages ทั้งหมดไปยัง API call

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

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)
แก้ไขและรันโค้ด