更多 assistant 消息!
在您之前的消息基础上扩展,添加更多示例,并分别存入 example1、response1、example2、response2、example3 和 response3。
让我们看看能否让模型按期望的格式输出信息!
本练习是课程的一部分
在 Python 中使用 DeepSeek
练习说明
- 扩展您之前的消息,加入其他国家的更多示例,并分别存入
example1、response1、example2、response2、example3和response3。
交互式实操练习
通过完成这段示例代码来试试这个练习。
client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")
response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Pro",
# Add in the extra examples and responses
messages=[
{"role": "system", "content": "You are a helpful Geography tutor that generates concise, one-sentence summaries for different countries."},
{"role": "user", "content": "Give me a quick summary of Portugal."},
{"role": "assistant", "content": "Portugal is a country in Europe that borders Spain. The capital city is Lisboa."},
{"role": "user", "content": ____},
{"role": "assistant", "content": ____},
{"role": "user", "content": ____},
{"role": "assistant", "content": ____},
{"role": "user", "content": ____},
{"role": "assistant", "content": ____},
{"role": "user", "content": "Give me a quick summary of Greece."}
]
)
print(response.choices[0].message.content)