文本摘要
DeepSeek 模型的一个常见用例是对文本进行摘要。在商业场景中非常实用,例如把冗长的报告压缩成精炼的单页或几条要点,或为不同相关方提取下一步行动和时间安排。
在本练习中,您将使用聊天模式的 DeepSeek,把一段关于金融投资的文本(finance_text)概括为两条简洁的项目符号要点。
本练习是课程的一部分
在 Python 中使用 DeepSeek
练习说明
- 使用 f-string 将
finance_text插入到prompt中。 - 创建请求并发送提供的
prompt;将最大 token 数设置为400。
交互式实操练习
通过完成这段示例代码来试试这个练习。
client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")
# Use an f-string to format the prompt
prompt = f"""Summarize the following text into two concise bullet points:
{____}"""
# Create a request to the chat model
response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Pro",
messages=[{"role": "user", "content": ____}],
____
)
print(response.choices[0].message.content)