文字摘要
DeepSeek 模型的一個常見用途是做文字摘要。這在商務情境非常實用,例如把冗長報告濃縮成精簡的一頁摘要或幾個重點項目,或是為不同利害關係人整理出後續行動與時程。
在本練習中,你會使用聊天模式的 DeepSeek,將一段關於金融投資的文字(finance_text)摘要成 2 個精簡的項目符號。
本練習屬於課程
使用 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.1-Flash",
messages=[{"role": "user", "content": ____}],
____
)
print(response.choices[0].message.content)