单示例提示:足够了吗?
正如您所见,最初的提示词还有改进空间。请尝试添加示例 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)