Generative AIPrompt engineeringCustomizing prompts

Provide context

5 minutes read

Engaging with an AI like ChatGPT can feel like magic. You type in a prompt, and it provides you with a detailed response, whether that's writing a poem, explaining a complex concept, or generating code. However, have you ever wondered why sometimes ChatGPT seems to understand you perfectly, while at other times, it might miss the mark? The secret lies in the context you provide in your prompt. In this topic, we'll explore how to give ChatGPT the right context to get the best possible output. We'll cover the importance of clear instructions, specificity, and array of relevant details.

What is context?

Let's pause for a moment to consider what "context" means here. When we talk to ChatGPT, the context is the background information that helps it understand our requests. It's like when you need to tell a friend a story, and you start by explaining the situation to set the scene. That's providing context.

The model doesn't have access to any external or real-world knowledge beyond what it was trained on, it doesn't remember past interactions either. Therefore, the context you supply in your prompt is the only information it has to generate a response.

By providing context, you're essentially guiding the AI's response. This can be particularly helpful in situations where you want the model to continue a certain narrative, answer a specific question, or maintain a particular tone. It's like giving the model a summary of a book before asking it to write the next chapter.

Context: first steps

Let's see some examples. We will not include the whole answer here due to its length, but you can experiment on your own.

First of all, consider a prompt without any context.

PROMPT:
What should I do to survive in this world? 
Give me a brief answer.
RESPONSE:
To survive in this world:

Take care of your basic needs: food, water, 
shelter, and clothing. Maintain good health: 
exercise regularly, eat a balanced diet, 
and get adequate rest. Seek education 
and continuous learning to adapt to changing environments.
<...>

That's helpful! ChatGPT has assumed that we live in a modern world with contemporary rules, which is understandable.

But does the context change the answer? Let's see:

PROMPT:
I am on a small tropical island with no people around 
because my ship sank in the ocean. 
What should I do to survive in this world? 
Give me a brief answer.
RESPONSE:
Surviving on a deserted tropical island 
requires addressing immediate needs 
and planning for long-term sustenance. 

Here's a brief survival guide:
Find Fresh Water: Look for streams, waterfalls, 
or collect rainwater. Avoid drinking saltwater 
or unsafe stagnant water.
Seek Shelter: Protect yourself from the elements. 
Use natural features or build a shelter from branches, 
leaves, and other materials.
<...>
Remember, your priorities are shelter, 
water, signaling, and food. 
Stay safe and focused on being rescued.

The priorities have slightly changed. If you change the setting to a zombie apocalypse in the countryside, the reply will change again. Try it!

As you can see, the context sets the stage for a series of events and gives us a clear picture of what's happening, where it's happening, and who's involved.

How do you provide good context?

The main idea of creating a good context is the following: mention all aspects that aren't common or standard. This could include the setting, city, country, area of work, background—basically, anything that will help ChatGPT get a clear picture of what exactly you need.

Let's gradually improve the prompt for better understanding.

  1. A bad example: "Write about AI for a class thing." This prompt is ineffective because it is vague and lacks specificity. It doesn't provide clear guidance on what aspect of AI to focus on or what the purpose of the writing is. "A class thing" is not even a defined task!

  2. Better example: "Prepare a short talk for your class about why learning AI is useful." This prompt is an improvement over the previous example, as it provides a bit more direction by asking for a talk that elucidates current uses of AI. The task is clear and the context is mentioned.

  3. A good example: "Imagine you're a student assigned with delivering a presentation to your peers in a technology seminar on the importance of AI skills in the modern world. Your goal is not only to inform but also inspire your classmates to engage with AI technology. Create a comprehensive plan for your presentation. Don't forget to include interactive elements such as a live demonstration or a Q&A session to encourage audience participation." This prompt is effective because it provides a clear objective (creating a presentation plan), a specific topic (the importance of AI skills), a setting (a technology seminar), and some guidance on what to include (interactive elements). It also suggests a persuasive angle (inspiring classmates) and actionable outcomes (developing AI skills).

However, be careful not to make the context too long, as the model has a maximum token limit. If your context is too long, it might limit the model's capacity to generate a meaningful response. We will focus on this aspect later in our materials.

Conclusion

Here's what we've covered:

  • What context means in a conversation with ChatGPT;

  • Why context is important for ChatGPT;

  • How to provide a good context when interacting with ChatGPT.

Mastering the art of providing context to ChatGPT can greatly enhance the quality and relevance of the responses you receive. It's all about setting the stage for the AI and guiding it in the right direction. So, the next time you interact with ChatGPT, remember to give it a bit of context!

8 learners liked this piece of theory. 0 didn't like it. What about you?
Report a typo