paint-brush
100 Days of AI Day 2: Enhancing Prompt Engineering for ChatGPTby@sindamnataraj
585 reads
585 reads

100 Days of AI Day 2: Enhancing Prompt Engineering for ChatGPT

by NatarajJanuary 4th, 2024
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

On day 2 of 100 Days of AI, we learn prompt engineering tips for optimal AI output.

Company Mentioned

Mention Thumbnail
featured image - 100 Days of AI Day 2: Enhancing Prompt Engineering for ChatGPT
Nataraj HackerNoon profile picture

I write a newsletter called Above Average, where I talk about the second-order insights behind everything that is happening in the big tech. If you are into tech and want to be above average, subscribe to it.


I don’t know if prompt engineering will actually become a role in companies in the future. But writing better prompts will become more and more important if you want to be more productive. So, to learn how to write better prompts to get the desired output, I did a short course on Deeplearning.ai called ChatGPT Prompt Engineering for Developers.


Here are some takeaways that will help you become a better prompter.


  1. Getting to the right Prompt with the desired output is an Iterative Process: You will not get the right prompt on the first try. You need to start with a basic prompt and refine it using the best principles (which I will talk about below). If you are a developer creating an application, you might want to test multiple similar prompts with large sets of data to evaluate the right prompt for your application.
  2. Principle 1 – Write clear and specific instructions: Clear doesn’t mean short. It means using delimiters (quotes, backticks, dashes, etc.) to highlight the text the prompt should work on. It means asking for a structured output. Explicitly ask the LLM to check whether the conditions you have instructed are satisfied. Or sometime giving explicit examples of successfully completing a task. In the example below, you can see how we used delimiters.
from openai import OpenAI
client = OpenAI()
client.api_key = 'YOUR_SECRET_KEY'

text_1 = f"""
Making a cup of tea is easy! First, you need to get somewater boiling. While that's happening,
grab a cup and put a tea bag in it. Once the water is
hot enough, just pour it over the tea bag.
Let it sit for a bit so the tea can steep. After a
few minutes, take out the tea bag. If you
like, you can add some sugar or milk to taste.
And that's it! You've got yourself a delicious
cup of tea to enjoy.
"""

prompt = f"""
You will be provided with text delimited by triple quotes.
If it contains a sequence of instructions, \
re-write those instructions in the following format:

Step 1 - ...
Step 2 - …
…
Step N - …

If the text does not contain a sequence of instructions, \
then simply write "No steps provided."

"""{text_1}"""

"""

response = client.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "user",
"content": prompt
}
],
temperature=0,
#max_tokens=64,
#top_p=1
)

print(response.choices[0].message.content)
  1. Principle 2 – Give the model time to think: Instead of directly asking the model to do the final goal you want to achieve, break down the goal into multiple tasks. Also, instruct the model to give the output in the format you require explicitly. Models tend to hallucinate and take the solution from the text you give instead of calculating independently, so explicitly tell the model to work its own solution.


That’s it for day 2 of 100 days of AI.


Follow me on Twitter for the latest updates on 100 days of AI, or bookmark this page.


Also published here.