針對 few-shot 提示的疊代式提示工程
你目前在一家內容製作公司的專案中工作。這個專案的目標是開發一個文字分類模型,能準確辨識並歸類文字中的不同情緒,例如快樂、悲傷與恐懼。若文字不包含可辨識的情緒,你希望模型回應「no explicit emotion」。
你決定使用提供的 few-shot prompt。不過,你發現「Time flies like an arrow」被錯誤分類為「surprise」。你現在的目標是調整 prompt,讓模型能把這個例子正確分類為「no explicit emotion」。
OpenAI 套件與 get_response() 函式已為你預先載入。
本練習屬於課程
使用 OpenAI API 的提示工程
練習說明
- 透過調整範例,疊代式地優化
prompt,使"They sat and ate their meal"這個例子的輸出為 no explicit emotion。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
client = OpenAI(api_key="")
# Refine the following prompt
prompt = """
Receiving a promotion at work made me feel on top of the world -> Happiness
The movie's ending left me with a heavy feeling in my chest -> Sadness
Walking alone in the dark alley sent shivers down my spine -> Fear
____
____
They sat and ate their meal ->
"""
response = get_response(prompt)
print(response)