in

Mastering Immediate Engineering to Unleash ChatGPT’s Potential | by Idil Ismiguzel | Jun, 2023


1. Summarize textual content and extract data

Summarizing data generally is a time-saving method, particularly when it’s essential extract key factors or particular particulars. With the ChatGPT API, we are able to leverage its capabilities to generate summaries for big volumes of textual content.

Taking the instance of the Disneyland critiques dataset, which consists of 42,000 critiques, we are able to ease the analysis course of by using summaries. Though I’ll exhibit with only one evaluation, the method can simply be scaled to deal with bigger portions of textual content.

To make use of ChatGPT API, you have to to login into your OpenAI account and generate your API key by navigating to “View API Keys” part from the suitable high nook. When you created your API key, it’s essential retailer it in a secure place and never show it.

# Set up openai 
pip set up openai

import os
import openai

# Safely retailer your API key
OPENAI_API_KEY = "sk-XXXXXXXXXXXXXXXXXXXXXXXX"
openai.api_key = OPENAI_API_KEY

We are going to now generate a helper operate that may take our immediate and return a completion for that immediate.

# Helper operate to return completion for a immediate

def get_completion(immediate, mannequin="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
mannequin=mannequin,
messages=messages,
temperature=0, # diploma of randomness of the response
)
return response.selections[0].message["content"]

# Enter one evaluation

evaluation = """
Have been to Disney World, Disneyland Anaheim and Tokyo Disneyland
however I really feel that Disneyland Hong Kong is admittedly too small to be
known as a Disneyland. It has method too few rides and points of interest.
Souvenirs, meals and even entrance tickets are barely extra
costly than different Disneyland as effectively. Mainly, this park is
good just for young children and individuals who has by no means been to Disney.
The meals selections have been acceptable, principally quick meals, and never too costly.
Bottled water, nevertheless, was VERY costly however they do have water
fountains round so that you can refill your water bottles. The parade was
fairly good. It was crowded not an issue however what was the issue was
the folks have been simply so impolite, the pushing and shoving reducing in traces
for the rides, reward retailers, meals stands was simply to a lot to take. overlook
making an attempt to see one of many reveals its a free for all for seats, i do not see
how Disney can let this occur, it was by far the worst managed Disney
property.
"""

# Write the immediate and generate the response utilizing the helper operate

immediate = f"""
Summarize the evaluation beneath in 30 phrases.
Evaluation: ```{evaluation}```
"""

response = get_completion(immediate)
print(response)

Disneyland Hong Kong is simply too small with few rides and points of interest. Meals and souvenirs are costly. Good for young children and first-time guests. Crowded with impolite folks and poorly managed.

The abstract is fairly nice and round 30 phrases as we requested within the immediate. If we would like we are able to additionally concentrate on a selected factor within the summaries e.g. worth and worth.

immediate = f"""
Summarize the evaluation beneath in 10 phrases and
focus worth and worth.
Evaluation: ```{evaluation}'''
"""

response = get_completion(immediate)
print(response)

Costly, small, and crowded Disneyland with few points of interest.

By producing a focused abstract, now we have reworked our preliminary evaluation right into a extra significant and impactful assertion. 🍄

Now, let’s take it a step additional and extract related data within the JSON format for simpler processing and integration with different techniques. We are going to outline a template for keys within the immediate.

immediate = f"""
Establish the next gadgets from the evaluation:
- Sentiment (constructive or destructive)
- Which Disney park was reviewed
- Is the reviewer expressing disappointment? (true or false)
- Is the reviewer expressing happiness? (true or false)

Format your response as a JSON object with
"Sentiment", "Park", "Anger" and "Happiness" because the keys.
Format the Anger and Happiness worth as a boolean.
Maintain the solutions brief.

Evaluation: ```{evaluation}```
"""
response = get_completion(immediate)
print(response)

{
“Sentiment”: “destructive”,
“Park”: “Hong Kong Disneyland”,
“Anger”: true,
“Happiness”: false
}

It’s fairly superb!

2. Translate the textual content

As you possibly can think about, if we are able to create summaries, we are able to additionally translate the textual content into totally different languages. Constructing on the earlier instance, we are going to now request summaries to be generated in English, Italian, and German languages.

immediate = f"""
Your job is to summarise the next evaluation.

Summarize the evaluation beneath in at most 10 phrases.
Print the abstract in English, Italian and German

Evaluation: ```{evaluation}```
"""

response = get_completion(immediate)
print(response)

Abstract:
English: Disneyland Hong Kong is small with few points of interest and costly.
Italian: Disneyland Hong Kong è piccolo con poche attrazioni e costoso.
German: Disneyland Hong Kong ist klein mit wenigen Attraktionen und teuer.

3. Increasing textual content

Increasing entails using a smaller textual content piece, and leveraging the capabilities of a giant language mannequin to generate a extra in depth piece of textual content. For instance, if we enter a buyer evaluation, we are able to produce an in depth reply e mail and handle the issues raised. We will present pointers for the format and content material.

immediate = f"""
Your job is to jot down an e mail reply to the shopper.
Given the shopper e mail delimited by ```.
Generate a reply to thank the shopper for his or her evaluation.

Tips:

- If the sentiment is constructive or impartial, thank the shopper
for his or her suggestions and confer with the particular particulars they talked about.
- If the sentiment is destructive, sincerely apologize for his or her poor
expertise, take accountability, and supply follow-up contact data.
- Specific appreciation for his or her time and evaluation. Discuss with specific
factors to construct rapport.
- For destructive experiences, apologize sincerely and settle for accountability.
Provide customer support contact data.
- Purpose for a concise but considerate tone.
- Shut professionally as an "AI buyer agent".
Buyer evaluation: ```{evaluation}```
"""

response = get_completion(immediate)
print(response)

Pricey valued buyer,

Thanks for taking the time to share your expertise at Disneyland Hong Kong. We admire your suggestions and are sorry to listen to that your go to didn’t meet your expectations.

We apologize for any inconvenience attributable to the restricted variety of rides and points of interest, in addition to the upper costs for souvenirs, meals, and tickets. We perceive that these elements can affect your total expertise on the park.

We’re glad to listen to that you just discovered the meals selections acceptable and that the parade was fulfilling. We additionally admire your suggestions concerning the crowds and impolite habits of some visitors. We take these issues severely and can work to enhance our administration of the park to make sure a extra fulfilling expertise for all visitors.

When you’ve got any additional issues or wish to present further suggestions, please don’t hesitate to contact our customer support crew at [insert contact information]. We worth your suggestions and hope to have the chance to offer a greater expertise for you sooner or later.

Thanks once more to your evaluation.

Finest regards,

AI buyer agent

Good job, AI buyer agent! ✉️

On this article, we explored the most effective practices of immediate engineering utilizing each the online UI and API. We mentioned a number of efficient immediate patterns, together with persona patterns, query refinement, templates, zero-shot, and chain-of-thought prompting. Moreover, we delved into using the ChatGPT API by producing our secret key and explored its capabilities in textual content summarization, translation, and growth.

I hope this tutorial evokes you to make use of giant language fashions to spice up your creativity and productiveness. I’m positive, it may well show you how to to generate concepts, acquire new insights, remedy advanced issues — and improve your day by day work at many ranges. The chances are huge! 🤖✨

🍓 If you happen to get pleasure from studying articles like this and want to help my writing, you might think about becoming a Medium member! Medium members get full entry to articles from all writers and in case you use my referral link, you’ll be instantly supporting my writing.

🍓 If you’re already a member and to learn my articles, you possibly can subscribe to be notified or follow me on Medium. Let me know when you’ve got any questions or strategies.


Past The Numbers: The Essential Function of Comfortable Expertise in Information Evaluation | by Iffat Malik Gore | Jun, 2023

Too Many Options? Let’s Have a look at Principal Element Evaluation | by Hector Andres Mejia Vallejo | Jun, 2023