One-shot prompting: เพียงพอหรือไม่?
จากที่เห็น พรอมต์เริ่มต้นยังมีจุดที่ปรับปรุงได้ ลองเพิ่มตัวอย่าง Love these! = 5 และใส่ = หลังรีวิวแต่ละรายการ เพื่อดูว่าจะช่วยให้ผลลัพธ์มีรูปแบบที่สม่ำเสมอและตัวเลขที่แม่นยำขึ้นได้หรือไม่
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การทำงานกับ OpenAI API
คำแนะนำการฝึกหัด
- เพิ่มตัวอย่าง
Love these! = 5ไว้ที่ต้นพรอมต์ และเพิ่ม=หลังรีวิวแต่ละรายการในพรอมต์ เพื่อระบุรูปแบบของผลลัพธ์ที่ต้องการ
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
client = OpenAI(api_key="")
# Add the example to the prompt
prompt = """Classify sentiment as 1-5 (negative to positive):
1. ____
2. Unbelievably good! ____
3. Shoes fell apart on the second use. ____
4. The shoes look nice, but they aren't very comfortable. ____
5. Can't wait to show them off! ____"""
response = client.chat.completions.create(model="gpt-4o-mini", messages=[{"role": "user", "content": prompt}], max_completion_tokens=100)
print(response.choices[0].message.content)