Do Not Use ChatGPT Only to "Summarize Text"
Summarizing text is one of the many tasks ChatGPT is extremely good at. Give it a piece of content and ask for a summary. You will be surprised how quickly it responds with a well-written summary.
But do not just ask for a summary.
By customizing your prompt, you can get ChatGPT to create much more than a plain summary.
Note: I will be using the OpenAI API with the Python library. You can use the same prompts in the web interface as well.
The first step is to import the libraries and create the API key:
import openai
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
openai.api_key = os.getenv('OPENAI_API_KEY')
OPENAI_API_KEY
is the environment variable that holds the API key, which can be obtained from the API Keys menu on OpenAI website.
The next step is to create a helper function for running the prompts.
def get_completion(prompt, model="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0,
)
return response.choices[0].message["content"]
Given a prompt, this function will return the output of the specified model, which is gpt-3.5-turbo by default.
Just a summary
The following is the product review I want to summarize.
review = """
I ordered this device (N300) to better extend WiFi signal to a Firestick on my small kitchen flat screen.
Device phone set-up was a bit convoluted, in the steps were keyed to some other phone, non an iPhone,
but close enough to figure it out. Once set up, the device definitely improved the push to the Firestick.
However, began to get curious about monitoring the Macard device while in operation. On the Firestick end,
one simply goes into setting/network, then WiFi ... push the (>II ) button to check connectivity.
Currently returns both signal and video quality 'very good.' So that's what the Firestick sees.
In the iPhone App Store, there is a one-star ""macard Wifi Wizard,"" which is supposed to be useful to
check the extender, download firmware updates, and so on. I downloaded it. It requests the email
one registered the device with, then advises it is sending an activation code. The code never arrives.
I contacted their support via chat; the rep acknowledged what I was saying and said he'd have
""the concerned department"" send me a code within 24 hours. It is now 48 hours. Nothing.
Thankfully, the device works.
"""
Let's start by asking only to "create a summary" of a product review.
prompt = f"""
Your task is to summarize a given product review.
The review is given below, delimited by triple quotes.
Review: ```{review}```
"""
response = get_completion(prompt)
Response: The reviewer purchased the N300 device to extend WiFi signal to a Firestick in their kitchen. The device setup was a bit confusing, but once set up, it improved the push to the Firestick. The reviewer tried to monitor the device using the "macard Wifi Wizard" app, but the activation code never arrived. They contacted support, but did not receive a response. Despite this, the device works well.
Limit the length
It sure is good enough but can get a lot better and fit our specific needs. For instance, we can limit the length of the summary.
prompt = f"""
Your task is to summarize a given product review.
Use at most 30 words.
The review is given below, delimited by triple quotes.
Review: ```{review}```
"""
response = get_completion(prompt)
I added "Use at most 30 words." in the prompt.
Response: The N300 WiFi extender improved signal to a Firestick, but the phone set-up was confusing. The Macard app didn't work, but the device itself works well.
It was able to extract the more important points from the review and limit the output to 30 words.
Only complaints
Consider a case where a product manager searches for only the negative comments and complaints about a product, which will be used for defining a roadmap to improve the product.
This can easily be done in the prompt.
prompt = f"""
Your task is to summarize a given product review.
Include only negative comments, concerns, and complaints in the summary.
The review is given below, delimited by triple quotes.
Review: ```{review}```
"""
response = get_completion(prompt)
Response: The device phone set-up was convoluted and the iPhone app for monitoring the device did not work. The activation code for the app was never received and customer support did not follow through on their promise to send a code within 24 hours.
The summary only includes the issues the user had. For instance, unlike the previous summaries, it does not include the "the device itself works well" part.
Specific points from multiple reviews
We are doing an analysis on device setup and want to learn if users have issues setting up the device. We can extract parts related to device setup from multiple reviews as follows:
prompt = f"""
Your task is to summarize multiple product reviews.
Include only the parts related to device setup.
The reviews are given below.
review_1: {review_1}
review_2: {review_2}
review_3: {review_3}
review_4: {review_4}
"""
response = get_completion(prompt)
Response: The device setup process was mentioned in all four reviews. Review 1 stated that the setup process was seamless after speaking with customer service. Review 2 mentioned that the device phone setup was a bit convoluted but once set up, the device worked well. Review 3 had difficulty setting up the device on a PC but was successful using a Kindle with the Silk browser. Review 4 found the setup process to be extremely easy and was able to use the device with their internet-based phone for work.
We were able to get parts related to device setup by customizing the prompt properly.
Here are the reviews used above if you'd like to read them or test it yourself:
review_1 = """
If anyone is curious - the reset is a light sequence of all 3 lights
The scanning is 1 solid blue and 1 flashing blue
And the successful connection is 2 solid blue lights.
I had difficulty with my original setup but spoke with the customer service line
and was able to walk through the process very seamlessly. The company is great at
making sure you are enjoying the product. So far it does seem to be helping,
the TV in my bedroom hasn't buffered since setting up.
"""
review_2 = """
I ordered this device (N300) to better extend WiFi signal to a Firestick on my small kitchen flat screen.
Device phone set-up was a bit convoluted, in the steps were keyed to some other phone, non an iPhone,
but close enough to figure it out. Once set up, the device definitely improved the push to the Firestick.
However, began to get curious about monitoring the Macard device while in operation. On the Firestick end,
one simply goes into setting/network, then WiFi ... push the (>II ) button to check connectivity.
Currently returns both signal and video quality 'very good.' So that's what the Firestick sees.
In the iPhone App Store, there is a one-star ""macard Wifi Wizard,"" which is supposed to be useful to
check the extender, download firmware updates, and so on. I downloaded it. It requests the email
one registered the device with, then advises it is sending an activation code. The code never arrives.
I contacted their support via chat; the rep acknowledged what I was saying and said he'd have
""the concerned department"" send me a code within 24 hours. It is now 48 hours. Nothing.
Thankfully, the device works.
"""
review_3 = """
I first tried to set this up using the procedure for PC. It got part way through it and froze.
After that I could not get it to even try. Running Microsoft 10 and Google Chrome. Don't know if that
has anything to do with it or not. Then I used my Kindle with the Silk browser, and it set up perfectly
first time. I then moved it half way across the house, plugged it in, turned it on, and I had strong Wi-Fi
all the way to the corner of the house. 1600 sq. ft., not at all "open concept".
"""
review_4 = """
I got this product to plug my internet based phone for work from home (Avaya desktop phone).
It works! The setup was EXTREMELY easy. At completion, I plugged the phone into the extender's ethernet
port and made a few phone calls which all worked perfectly with complete clarity. VERY happy with this
purchase since a cordless headset is around $250 (which I would have needed since the phone had to be
at the ethernet port on the wall). I recommend this product!
"""
Priority list
Let's say we have hundreds of reviews and need to create a priority list of the issues for improving the product. The list will be based on what customers do not like about or have problems with our product.
ChatGPT can create this list for us.
prompt = f"""
Your task is to summarize multiple product reviews.
I want to improve the product.
Create a priority list of 3 issues mentioned in the reviews.
The reviews are given below.
review_1: {review_1}
review_2: {review_2}
review_3: {review_3}
review_4: {review_4}
"""
response = get_completion(prompt)
Response:
Priority list of 3 issues mentioned in the reviews:
Difficulty in setting up the device using the PC and the need for clearer instructions.
Issues with the Macard Wifi Wizard app and the need for better customer support.
The need for clearer instructions on the device's compatibility with different types of phones.
It's already quite useful even if we did it for only 4 reviews. Imagine you have hundreds of reviews to be analyzed to create such a priority list. The time and effort ChatGPT saves is just incredible.
Unleash the lion
The full potential of ChatGPT is beyond what we can observe at the first glance. The key to discover utilizing its true capabilities and efficiency lies in carefully crafting and customizing prompts.
By strategically structuring prompts, we can guide the model towards more accurate, contextually relevant, and detailed responses.
You can become a Medium member to unlock full access to my writing, plus the rest of Medium. If you already are, don't forget to subscribe if you'd like to get an email whenever I publish a new article.
Thank you for reading. Please let me know if you have any feedback.