Few-shot prompting cho đánh giá sản phẩm
Bạn làm việc cho BrightCart, một nền tảng thương mại điện tử. Các trang sản phẩm hiện hiển thị huy hiệu AI “Quick-Read” để cô đọng hàng nghìn đánh giá của khách hàng thành những insight ngắn gọn. Để đơn giản hóa hơn nữa, bạn sẽ tách tóm tắt thành hai câu: câu đầu là điểm tích cực nổi bật, câu thứ hai là một mối lo ngại trung thực.
Hướng dẫn Claude đúng định dạng đó bằng few-shot prompting để mọi sản phẩm về sau đều có phần tóm tắt cân bằng như nhau.
Thư viện anthropic, client, và một mẫu raw_review đã được nạp sẵn.
Bài tập này là một phần của khóa học
Nhập môn các mô hình Claude
Hướng dẫn bài tập
- Đặt vai trò đúng cho phản hồi ví dụ đầu tiên của Claude.
- Yêu cầu viết tóm tắt 2 câu về sản phẩm.
- Truyền toàn bộ mảng
messagesvào lời gọi API.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
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)