单样例提示(One-shot prompting):足够了吗?
如您所见,最初的提示词还有改进空间。请尝试添加一个示例 Love these! = 5,并在每条评论后加上 =,看看是否能得到更一致的格式和更准确的分数。
本练习是课程的一部分
在 Python 中使用 DeepSeek
练习说明
- 在提示词的开头添加示例
Love these! = 5,并在提示词中的每条评论后添加=,以指明结果的格式应如何书写。
交互式实操练习
通过完成这段示例代码来试试这个练习。
client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")
# Add the example to the prompt
prompt = """Classify sentiment as 1-5 (negative to positive). Return no explanations:
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="deepseek-ai/DeepSeek-V4-Pro", messages=[{"role": "user", "content": prompt}], max_tokens=500)
print(response.choices[0].message.content)