As a developer, I use AI on a daily basis to optimize my workflow, automate certain tasks and get quick answers to my questions.
In this article, I'm going to share with you 6 tips for optimizing your prompts on chatGPT (generative AI) to get quality results.
Prompt Engineering is considered a science because it requires a thorough and methodical understanding of how language patterns respond to different prompts.
Like any science, it evolves with research and experience, making mastery of its fundamentals easier and easier to grasp as LLMs become more complete.
But first, what is a prompt?
A prompt is an instruction given to an artificial intelligence model to generate a response or perform a specific task.
It can be a sentence, a question, a paragraph or even a document that serves as a starting point.
The prompt establishes the context in which the AI must reason, clarifies what is expected in terms of content and format, and directs the response towards a specific domain or expertise.
A well-designed prompt optimizes relevance by minimizing ambiguities and errors.
Here are the key principles to keep in mind when designing effective prompts
-
Clarity and precision: A prompt must be clear and precise to obtain accurate responses.
-
Accurate context: Providing sufficient context allows the AI to better understand and respond appropriately.
-
Simplicity: A simple, straightforward prompt limits the risk of confusion and improves the quality of the answers generated.
1. Use AI itself to generate prompts
Yes, it sounds obvious, but it's often overlooked. AI is the best source for generating prompts, because it knows what works best for it.
Why is this? Generative AI works largely on the basis of examples it has seen. By giving her prompts that resemble what she's already seen, you increase your chances of getting quality responses.
She trains on billions of pieces of data, so why not ask her for a hand?
To do this, you can use prompts like:
-
"As an expert on [subject], I need you to make me an optimized prompt so that I can effectively learn the key principles of [subject], with concrete examples to speed up my learning process."
-
"You know [subject] inside out. I need you to give me an optimized prompt so that I can effectively learn the key principles of [subject]"
Example of use:
Human-generated prompt:
- I need you to make me an optimized prompt so that I can effectively learn the key principles of machine learning.
AI-generated prompt result:
- Context: I'm a beginner in machine learning and I'd like to understand the basics so I can progress quickly. My goal is to master essential concepts such as classification, regression, overlearning, and evaluation metrics. I'm also interested in simple practical examples and clear explanations. Request: Explain to me the key principles of machine learning (classification, regression, overlearning, evaluation metrics) in simple terms. Use analogies if possible to facilitate my understanding. Also provide a concrete example of each concept with pseudocode or practical explanations. "*
Tools for generating prompts
Tools exist to help you generate quality prompts.
Anthropic AI offers a tool that lets you generate customized prompts for chatGPT in just a few clicks.
2. Focus on specific and targeted prompts
Specific, targeted prompts help the AI to better understand what you want it to do.
Open-ended questions without a clear context can lead to imprecise or off-topic responses.
Specific, targeted prompts, on the other hand, guide the AI towards the expected response.
AI works word by word: the more information you give it, the more likely it is to produce an accurate answer.
Ineffective phrases:
-
"Tell me everything you know about artificial intelligence."
-
"What are the applications of artificial intelligence?"
Effective phrases:
-
"馃挕 I only have a weekend to visit Paris. Can you suggest an optimized itinerary to see the main monuments, avoiding the museums, as I don't want to stay inside? "
-
"馃挕 I'm having a problem with my Python code where I have to read a text file and extract lines that contain a certain keyword. Can you give me a simple example in Python that illustrates how to do this efficiently? "
3. Memory usage
Positive points
If you want to have AI generate consistent responses, it's important to manage its conversational context.
For example, you need to write several Linkedin posts on different topics.
You want each post to have the same style, tone and structure.
Bingo, that's where short-term memory comes in.
How it works
Based on the same example:
- Give context to the AI: I'm a digital marketing expert and I want to write several Linkedin posts on different topics. I want the style, tone and structure of each post to be similar to this one: [sample post].
You need to make your intentions clear to the AI.
All that's left is to ask it to write you a post on a specific topic, and it will remember the context you've given it.
Negative points
The AI has a limited memory (for now at least), and can be influenced by previous prompts.
Although short-term memory is interesting and practical, it can sometimes be an obstacle to generating accurate answers.
To avoid this, we recommend clearing the AI's memory when you change topic or context.
What's more, chatGPT has recently added a long-term memory option that allows you to store information on each and every prompt.
This feature is very useful for long and complex conversations, but it can also be a source of errors if not used correctly.
I recommend disabling it if you don't need it, or limiting it to essential information to avoid errors.
4. Use the internet search option
Generative AI is very effective, but it is trained on past data.
The world is changing fast, and it's important to keep in mind that AI doesn't have access to real-time news.
For this reason, OpenAI (and other generative AIs) offers an internet search option that allows the AI to consult information in real time to generate more accurate answers.
This provides it with up-to-date data and guarantees the relevance of the answers.
5. Analysis, feedback and iteration
Analysis of AI-generated responses is essential to assess the quality of prompts and replies.
You may think that the AI will give you the best possible answer on the first try, but this is rarely the case.
It's for this very reason that it's important to question the answers generated.
For example, you can say after an answer:
-
"Can you rephrase your answer using simpler terms?"
-
"I'm not sure I understand what you mean. Can you explain it more clearly?"
-
"Are you sure about this? Can you check on the internet to confirm your answer?" (if the internet search option is enabled)
Don't hesitate to iterate these requests for clarification to obtain a satisfactory answer.
Request for correction
Another very frequent use case is to ask the AI to analyze or correct content (e-mail, assignment, code...).
When writing your prompt, the advice I like to give is to end your request with an open-ended question.
Example:
-
"What do you think?"
-
"What's jumping out at you?"
-
"[...] I know you've noticed something wrong?"
To give you the most rational and authentic answer, you can also add details like:
-
"Be brutally honest, I prefer you to be direct."
-
"I'm open to criticism, so don't hesitate to tell me what you think."
-
"I'm ready to hear anything, so let go, take off the filters."
6. Curb chatGPT
Finally, my last piece of advice is to throttle chatGPT.
ChatGPT is a very powerful AI, but it can sometimes be too creative or too talkative.
To ensure optimal rendering quality, you can restrict the AI's responses by putting constraints on it.
For example, you can ask it not to exceed a certain number of words, not to use technical terms, and so on.
In the context of code generation, you can ask it not to use methods that are too advanced, or set constraints on the complexity of the generated code.
Conclusion
So, optimizing prompts is an iterative process that requires practice and patience. Prompt engineering is an essential skill, especially in the years to come when generative AI will play an increasingly important role in our daily lives.
For the first time in human history, we have access to so much knowledge and resources so easily. The problem-feedback cycle has been accelerated to such an extent that progress can be made at lightning speed. The opportunity is there, it's up to you to seize it.
Bibliography :
OpenAI
Date : Not specified
Titre : "Prompt Engineering Guide"
Source : https://platform.openai.com/docs/guides/prompt-engineering
Elliott Pierret
Date : Nov 13, 2024
Titre : "Generate PERFECT prompts with the AI Prompt Generator!"
Source : https://www.youtube.com/watch?v=vaG_lMfXBwE&t=110s