Self-consistency प्रॉम्प्ट्स
मान लीजिए आप एक स्टोर के मालिक हैं जो लैपटॉप और मोबाइल फोन बेचता है। दिन की शुरुआत में आपके पास स्टोर में 50 डिवाइस हैं, जिनमें से 60% मोबाइल फोन हैं। दिन भर में तीन ग्राहक स्टोर पर आए, हर एक ने एक-एक मोबाइल फोन खरीदा, और उनमें से एक ने अतिरिक्त रूप से एक लैपटॉप भी खरीदा। इसके अलावा, आपने अपनी इन्वेंटरी में 10 लैपटॉप और 5 मोबाइल फोन जोड़ दिए। दिन के अंत तक आपके पास कितने लैपटॉप और मोबाइल फोन होंगे? यह समस्या problem_to_solve स्ट्रिंग में दी गई है, और आप इसे हल करने के लिए self-consistency प्रॉम्प्ट का उपयोग करेंगे.
OpenAI पैकेज और get_response() फंक्शन आपके लिए पहले से लोड हैं.
इस अभ्यास में get_response() फंक्शन max_tokens पैरामीटर का उपयोग करता है ताकि यह अभ्यास तेज़ी से चल सके.
यह अभ्यास पाठ्यक्रम का हिस्सा है
OpenAI API के साथ Prompt Engineering
अभ्यास निर्देश
- ऐसा
self_consistency_instructionबनाएँ जो मॉडल को तीन विशेषज्ञों के साथ समस्या हल करने दे और परिणामों को majority vote से संयोजित करे. - अंतिम
promptबनाएँ, जिसमेंself_consistency_instructionऔरproblem_to_solveको जोड़ा गया हो.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
client = OpenAI(api_key="")
# Create the self_consistency instruction
self_consistency_instruction = ____
# Create the problem to solve
problem_to_solve = "If you own a store that sells laptops and mobile phones. You start your day with 50 devices in the store, out of which 60% are mobile phones. Throughout the day, three clients visited the store, each of them bought one mobile phone, and one of them bought additionally a laptop. Also, you added to your collection 10 laptops and 5 mobile phones. How many laptops and mobile phones do you have by the end of the day?"
# Create the final prompt
prompt = ____
response = get_response(prompt)
print(response)