One-shot 提示:這樣夠嗎?
如你所見,你的初始提示詞還有改進空間。試著加入一個範例 Love these! = 5,並在每則評論後面加上 =,看看是否能得到更一致的格式與更準確的數字。
本練習屬於課程
Working with the 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)