Zero-shot 提示:評論情緒分類
除了能回答問題、轉換文字與產生新內容之外,OpenAI 的模型也能用於分類任務,例如類別歸納與情緒分析。
在這個練習中,你將使用來自一家名為 Toe-Tally Comfortable 的線上鞋店的評論,探索如何用 OpenAI 的聊天模型進行情緒分類。
本練習屬於課程
Working with the OpenAI API
練習說明
- 定義一個
prompt,使用數字1到5來將給定敘述的情緒分類(由正面到負面)。 - 建立對 Chat Completions 端點的請求,將這個提示送給
gpt-4o-mini。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
client = OpenAI(api_key="")
# Define a multi-line prompt to classify sentiment
prompt = """____:
1. Unbelievably good!
2. Shoes fell apart on the second use.
3. The shoes look nice, but they aren't very comfortable.
4. Can't wait to show them off!"""
# Create a request to the Chat Completions endpoint
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": ____}],
max_completion_tokens=100
)
print(response.choices[0].message.content)