開始使用免費開始

文字摘要

使用 OpenAI 模型最常見的情境之一就是做文字摘要。這在商業場景有非常多應用,例如把長篇報告整理成精簡的一頁摘要或幾個重點條列,或是為不同利害關係人萃取後續步驟與時間表。

在這個練習中,你將使用對話式補全模型,把一段關於金融投資的文字(finance_text)摘要為兩個精簡的條列重點。

本練習屬於課程

Working with the OpenAI API

檢視課程

練習說明

  • 使用 f-string 將 finance_text 插入 prompt
  • 建立請求並送出提供的 prompt;最多使用 400 個權杖(tokens)。

動手互動練習

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

client = OpenAI(api_key="")

# 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 Completions endpoint
response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "user", "content": prompt}],
  ____
)

print(response.choices[0].message.content)
編輯並執行程式碼