Prompt Engineering for Development
In the context of AI, a prompt is the input you provide to the model to elicit a specific response. This can take various forms, ranging from simple questions or keywords to complex instructions, code snippets, or even creative writing samples. The effectiveness of your prompt directly influences the quality and relevance of the AI's output. — Google Cloud
Prompt engineering, according to the Google Cloud Introduction to Prompt Engineering release, is the art and science of designing and optimizing prompts to guide AI models, particularly LLMs, towards generating the desired responses. By carefully crafting prompts, you provide the model with context, instructions, and examples that help it understand your intent and respond in a meaningful way. Think of it as providing a roadmap for the AI, steering it towards the specific output you have in mind.
So for development, you just take the above answer and apply it to coding with an IDE agent.
Here's a few things that can up your prompt engineering game
1. Proper Context
Context in its real sense means the surrounding text, background, or situation that helps explain the full meaning of a word, phrase, or event.
Let me use an example: say you have a boyfriend and you see them on their phone, talking and laughing. It's a woman on the other end and you caught a snippet of the name saved as “my love”. Your first assumption is that they are cheating, because your name is babe and this foreign woman is “my love”.
Very sure of your assumptions, you start hollering and shouting at your boyfriend for cheating. The moment you pick up the phone to shout at the person on the other end, turns out it's your boyfriend’s mum and not Nkechi, who he’s in fact cheating on you with.
You start apologizing to the mom because “YOU DIDN'T KNOW”. That's how context works.
finding out your boyfriend's mom is saved as My love in his phonebook is proper context, as to why he will be laughig with a woman saved as my My love on the phone
AI will assume on your behalf, it will manufacture stuff, it will accuse your mother if you don't give it proper context.
So context in prompt engineering refers to the entire information environment provided to a Large Language Model (LLM) at inference time.
If you paid any attention to any of my tutorial videos, you’d see that at some point, I copy the inspo behind what I want to recreate to send to the LLM. It's not because I can't explain it to it, but with that image, it knows the exact placement of things.
Since I uploaded the image, it's within its context window; when I mention I want something here and there in the build, it refers back to the image it already has to be able to give me my desired output.
2. Instructions and Required Output
Aside from context, what makes up a good prompt? After proper context, you also need an instruction.
If you just give the agent context, it's going to ask what it's for, or if it's dumber, it's going to infer meaning.
Say you are in your IDE and you tell your IDE agent “Take a look at implementation.md”. implementation.md is now context in this case, and “take a look at” is the instruction.
It will go to the implementation file and come back with “I have checked the implementation file”.
If the implementation file contains instructions, it's going to follow them; if it doesn't, it's just going to come back with “I have checked the file, what do you need me to do?”.
That's input tokens and output tokens wasted.
But take a look at this: “Go to implementation.md, implement the instructions there. After you are done, draft up an implementation report.md file that contains every change you made when you followed the instructions in the implementation.md file.”
It gives implementation.md as context, "follow the instructions there" as command, and "write the implementation report.md file" as requirement or required output (visible output from following the command, because your command already triggered an output, which are the changes made when the agent follows the instructions in the implementation.md file).
Meaning a good prompt has context, instructions on what to do with the context, and requirements that the output should have.
If you didn't understand anything, take this home: context---instruction----required output.
3. Conversational vs. One-Shot Prompts
Now on the side, these agents are very much advanced, so you can actually use conversation to build up context, and you can keep changing the instruction and keep changing the output you want.
That's why I start most of my conversations with AI with “HI”, then after a response, I say “here’s what I want”. Maybe ten back-and-forths later, I say “oh, this is how I want it”.
You just need to follow the principles above whilst keeping it conversational, or you can be Mr. Complicated and write a thousand-line prompt that one-shots the whole thing.
But first principles should be followed with either one: Context–instruction–requirement, in no particular order.
This will take your coding with AI development game to another level.
Further Reading
For a more structured learning format, you should read this: https://cloud.google.com/discover/what-is-prompt-engineering
Comments
No comments yet. Be the first!