ChatGPT to NotionChatGPT to Notion

Summary Applications

on a month ago

Summary Applications

In today’s world, there is so much text that almost no one has enough time to read all the texts they wish to read. Therefore, one of the most exciting applications of large language models I see is using them to summarize text. This is something I’ve observed multiple teams building into various software applications.

You can do this in the ChatGPT web interface. I often use it to summarize articles, allowing me to consume more content than I could before. If you want to implement this in a more automated way, you’ll see how to do that in this lesson. Let’s dive into the code to see how to use it for text summarization. We’ll start with the same setup code as before: importing OpenAI, loading the API key, and the getCompletion helper function.

Summarizing

In this lesson, you will summarize text with a focus on specific topics.

Setup

python

`In [1]: import openai
import os
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv()) # 读取本地.env文件
openai.api_key = os.getenv('OPENAI_API_KEY')

In [2]: def get_completion(prompt, model="gpt-3.5-turbo"):
# Andrew Andrew mentioned that the prompt/completion paradigm is pre - set
messages = [{"role":"user","content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0,
)
return response.choices[0].message["content"]`

I’ll use a running example: the task of summarizing product reviews. For instance, "I got this panda plush toy as a birthday gift for my daughter, and she loves it so much that she takes it everywhere." If you’re building an e-commerce website with large amounts of (large amounts of) reviews, a tool to summarize lengthy reviews can help you quickly browse more reviews and better understand customer feedback. Here’s a prompt for generating a summary: "Your task is to generate a brief summary from product reviews on an e-commerce website, summarizing the review in under 30 words."

Notes:

  • Technical terms (e.g., "temperature" in the model) are translated contextually as "summary-applications" (degree of randomness).
  • Code blocks are preserved, with only comments and natural language text translated.
  • Chinese terms like "large amounts of" (large amounts of) are used to replace placeholder English where necessary.
Summary Applications