MulaiMulai sekarang secara gratis

Text summarization

One really common use case for using OpenAI models is summarizing text. This has a ton of applications in business settings, including summarizing reports into concise one-pagers or a handful of bullet points, or extracting the next steps and timelines for different stakeholders.

In this exercise, you'll summarize a passage of text on financial investment (finance_text) into two concise bullet points using a chat completion model.

Latihan ini adalah bagian dari kursus

Working with the OpenAI API

Lihat Kursus

Petunjuk latihan

  • Use an f-string to insert finance_text into prompt.
  • Create a request, sending the prompt provided; use a maximum of 400 tokens.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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)
Edit dan Jalankan Kode