พรอมต์แบบ Self-consistency
สมมติว่าคุณเป็นเจ้าของร้านที่จำหน่ายแล็ปท็อปและโทรศัพท์มือถือ เริ่มต้นวันด้วยสินค้าในร้าน 50 เครื่อง โดย 60% เป็นโทรศัพท์มือถือ ตลอดวัน มีลูกค้า 3 รายมาที่ร้าน แต่ละรายซื้อโทรศัพท์มือถือ 1 เครื่อง และหนึ่งในนั้นซื้อแล็ปท็อปเพิ่มอีก 1 เครื่อง นอกจากนี้ยังเพิ่มสินค้าเข้าคลัง ได้แก่ แล็ปท็อป 10 เครื่อง และโทรศัพท์มือถือ 5 เครื่อง เมื่อสิ้นวัน จะมีแล็ปท็อปและโทรศัพท์มือถือรวมกี่เครื่อง? โจทย์นี้ถูกกำหนดไว้ในสตริง problem_to_solve และจะใช้ self-consistency prompt ในการแก้ปัญหา
แพ็กเกจ OpenAI และฟังก์ชัน get_response() ถูกโหลดไว้ให้แล้ว
ฟังก์ชัน get_response() ในแบบฝึกหัดนี้ใช้พารามิเตอร์ max_tokens เพื่อช่วยให้แบบฝึกหัดทำงานได้เร็วขึ้น
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Prompt Engineering กับ OpenAI API
คำแนะนำการฝึกหัด
- สร้าง
self_consistency_instructionที่ให้โมเดลแก้ปัญหาโดยใช้ ผู้เชี่ยวชาญสามคน และรวบรวมผลลัพธ์ด้วย การลงคะแนนเสียงข้างมาก - สร้าง
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)