開始使用免費開始

使用 Claude 進行文字摘要

你是電玩公司 Nebula Forge Games 的內容策略師,正準備推出最新一代的 Skybound Legends。開發團隊剛發表一篇介紹新功能的開發者文章,但你需要為社群媒體受眾擷取一段宣傳文。 請把該文章濃縮為 2 句、具吸引力且適合社群媒體的前導文。

anthropic 函式庫、client,以及 article_text 字串都已預先載入。

本練習屬於課程

Claude 模型入門

檢視課程

練習說明

  • 設定系統訊息,建立適合社群媒體受眾、具吸引力且容易理解的語氣。
  • 建立一個使用者提示,要求對文章進行「2-3 句」的摘要。
  • 設定 max_tokens,將回應限制為 100 個 tokens。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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)
編輯並執行程式碼