Prompt engineering

James Gnanasekaran
4 min readJun 5, 2023

--

Photo by Mojahid Mottakin on Unsplash

Deeplearning.AI, in partnership with OpenAI, presents a course (free for a limited time) on “ChatGPT prompt engineering for developers”

Course Highlights:
✅ Short and concise curriculum
✅ Jupyter notebook for interactive practice with prompts
🔗 Enroll now:

ChatGPT Prompt Engineering for Developers — DeepLearning.AI

Here is a quick summary of the key learnings from this course.

How to converse with an AI Large Language Model(LLM)?

The instructions given to the model is called a prompt.

Two key principles when providing a prompt:

  1. Use delimiters (tick marks, triple backticks). Also helps to avoid prompt injections
  • Ask for structured output (HTML, JSON, XML, etc.)
  • Check whether conditions are satisfied. Check the assumptions required to do the task.
  • Few shot prompting (Give successful examples of completed tasks)

2. Give the model time to think

  • Specify the steps required to complete a task
  • Instruct the model to work out its own solution before rushing to a conclusion

Watch out for hallucinations!

The large language models are based on generative AI, which means that it tries to generate the next sequence of words based on what it has been trained on. If it has to respond to something which wasn’t part of the training data, it could come up with answers that sound plausible but are not true. In the AI world, this is called hallucination. Be aware of this limitation.

Prompt development is iterative.

You most likely won’t arrive at the perfect prompt the very first time. You need to see the results of the model and fine-tune your prompt. Keep the key principles in mind.

Control the temperature

Temperature — this parameter alters the degree of randomness in the response

  • Zero temperature; use it when you require predictability.
  • Higher temperature, more variations

Interesting use cases

Asking the model to generate a marketing product description from a product fact sheet for a chair, with the writing style suited for the intended audience, keeping a limit on the number of words, and also getting the dimensions in an HTML table

prompt = f"""
Your task is to help a marketing team create a
description for a retail website of a product based
on a technical fact sheet.

Write a product description based on the information
provided in the technical specifications delimited by
triple backticks.

The description is intended for furniture retailers,
so should be technical in nature and focus on the
materials the product is constructed from.

At the end of the description, include every 7-character
Product ID in the technical specification.

After the description, include a table that gives the
product's dimensions. The table should have two columns.
In the first column include the name of the dimension.
In the second column include the measurements in inches only.

Give the table the title 'Product Dimensions'.

Format everything as HTML that can be used in a website.
Place the description in a <div> element.

Technical specifications: ```{fact_sheet_chair}```
"""

response = get_completion(prompt)
print(response)

Summarizing product review focusing on aspects that are specific for a particular department, like focusing on comments related to pricing.

prompt = f"""
Your task is to generate a short summary of a product \
review from an ecommerce site to give feedback to the \
pricing deparmtment, responsible for determining the \
price of the product.

Summarize the review below, delimited by triple
backticks, in at most 30 words, and focusing on any aspects \
that are relevant to the price and perceived value.

Review: ```{prod_review}```
"""

response = get_completion(prompt)
print(response)

Inferring topics from a given text. We can restrict the model to also choose from a set of topics. Imagine if we are interested to find out from a set of customer reviews which team needs to take action whether the review addresses product, price, shipping

Furthermore, it can do translation, spellcheck/Grammar check, expand a given text and generate customer service emails that are tailored to each customer’s review

Chatbot

I have experience building chatbots with Google Dialogflow. A few years back, it was one of the easiest ways to build a bot. You need to give example phrases to train the model to identify the intent of the conversation.

However, with LLMs, building chatbots has become really easy and way faster. The course gives an example of an order bot for a pizza restaurant. The bot collects the order by clarifying options, extras, and sizes and then confirms the order. The menu is given as text within the prompt itself.

Here is an example of an Insurance claim bot that assists the customer in knowing the status of their claims. I built this bot with Google Dialogflow a few years back, which was one of the easiest ways to build a bot.

It took me a few days to build the bot then, and now with LLM, the same bot can be built in less than an hour.

As you can see,

  • You don’t have to define each and every intent
  • You can just tell the model the task, and it gets it
  • No need to define ‘small talks’; handles out of context conversation gracefully
  • Performs validation of the data; it validated the postcode based on the regex I gave

Hope you are inspired to take up this prompt engineering course. Curious to know what you build, share in the comments.

Remember, always use the model responsibly and in a way that helps people!

--

--

James Gnanasekaran

Lifelong learner, Interested in solving business problems with technology, with a specific interest in CV and NLP (https://www.linkedin.com/in/jamespaultg/)