प्रोडक्ट रिव्यूज़ के लिए few-shot prompting
आप BrightCart नाम के एक e-commerce प्लेटफ़ॉर्म में काम करते हैं. प्रोडक्ट पेज अब AI "Quick-Read" बैज दिखा रहे हैं, जो हज़ारों कस्टमर रिव्यूज़ को छोटे-छोटे इनसाइट्स में समेट देता है. इन इनसाइट्स को और सरल बनाने के लिए, आप सारांश को दो वाक्यों में बाँटेंगे: पहला वाक्य सबसे प्रमुख सकारात्मक निष्कर्ष, और दूसरा वाक्य एक ईमानदार चिंता.
हर आने वाले प्रोडक्ट के लिए एक जैसा संतुलित सारांश मिले, इसके लिए few-shot prompting के ज़रिए Claude को वही सटीक फ़ॉर्मेट सिखाइए.
anthropic लाइब्रेरी, client, और एक raw_review सैंपल पहले से लोड हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Claude मॉडलों का परिचय
अभ्यास निर्देश
- Claude के पहले उदाहरण उत्तर के लिए सही role सेट करें.
- प्रोडक्ट के बारे में 2-वाक्य का सारांश लिखने के लिए कहें.
- पूरी
messagesarray को API कॉल में पास करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
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)