Forum Discussion
Introduction to Prompt Engineering
With GPT-3, GPT-3.5, and GPT-4 prompt-based models, the user interacts with the model by entering a text prompt, to which the model responds with a text completion.
Basic concepts and elements of GPT prompts
Prompt components
- Instructions
- Primary Content
- Examples
- Cue
- Supporting content
Prompts Basics
Text prompts are how users interact with GPT models
GPT models attempt to produce the next series of words that are most likely to follow from the previous text.
Prompts | Best Practices
- Be Specific: Leave as little to interpretation as possible. Restrict the operational space
- Be Descriptive: Use analogies
- Double Down:Sometimes you may need to repeat yourself to the model. Give instructions before and after your primary content, use an instruction and a cue, etc.
- Order Matters:The order in which you present information to the model may impact the output. Whether you put instructions before your content (“summarize the following…”) or after (“summarize the above…”) can make a difference in output. Even the order of few-shot examples can matter. This is referred to as recency bias.
- Give the model an “out” :It can sometimes be helpful to give the model an alternative path if it is unable to complete the assigned task. For example, when asking a question over a piece of text you might include something like "respond with ‘not found’ if the answer is not present". This can help the model avoid generating false responses
Prompt components
Instructions
When we show up to the present moment with all of our senses, we invite the world to fill us with joy. The pains of the past are behind us. The future has yet to unfold. But the now is full of beauty simply waiting for our attention.
- Instructions are likely the most commonly used prompt component
- Instructions - instruct the model on what to do
Space efficiency
As shown in the examples in the previous section, GPT models can understand tabular formatted data quite easily. This can be a space efficient way to include data, rather than preceding every field with name (such as with JSON).
Consecutive whitespaces are treated as separate tokens which can be an easy way to waste space. Spaces preceding a word, on the other hand, are typically treated as part of the same token as the word. Carefully watch your usage of whitespace and don’t use punctuation when a space alone will do.
Advanced techniques in prompt design and prompt engineering
Certain models expect a specialized prompt structure
For Azure OpenAI GPT models, there are currently two distinct APIs where prompt engineering comes into play:
- Chat Completion API
- Completion API
- Each API requires input data to be formatted differently
Use of affordances | Factual claims, Search queries and Snippets
Factual claims:
- John Smith is married to Lucy Smith
- John and Lucy have five kids
- John works as a software engineer at Microsoft
Search queries:
- John Smith married to Lucy Smith
- John Smith number of children
- John Smith software engineer Microsoft
Snippets:
[1] … John Smith’s wedding was on September 25, 2012 …
[2] … John Smith was accompanied by his wife Lucy to a party
[3]John was accompanied to the soccer game by his two daughters and three sons
[4] … After spending 10 years at Microsoft, Smith founded his own startup, Tailspin Toys
[5] John M is the town smith, and he married Fiona. They have a daughter named Lucy
System message framework and template recommendations for Large Language Models (LLMs)
- Define the specific task(s)
- Define how the model should complete the tasks
- Define the scope and limitations
- Define the posture and tone
- Define the language and syntax
- Define any styling or formatting
- Describe difficult use cases
- Show the potential “inner monologue”
- Identify and prioritize the harms you’d like to address.