使用 Claude 进行文本摘要
您是电子游戏公司 Nebula Forge Games 的内容策划,正准备发布 Skybound Legends 的最新版本。开发团队刚发布了一篇介绍新特性的开发者文章,但您需要为社交媒体受众提炼一段文案。 请将该文章压缩为适合社交媒体阅读的、具有吸引力的 2 句预告。
anthropic 库、client 和字符串 article_text 已预加载。
本练习是课程的一部分
Claude 模型入门
练习说明
- 设置系统消息,确定适合社交媒体受众的生动、易懂语气。
- 创建一个用户提示,请求对文章进行 2-3 句 的总结。
- 设置
max_tokens,将回复限制为 100 个 token。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Set up system message for social media tone
system_msg = "____"
# Create the summarization prompt with length constraint
user_prompt = f"____: {article_text}"
# Make API call with appropriate parameters
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=____,
system=system_msg,
messages=[
{"role": "user", "content": user_prompt}
])
print(response.content[0].text)