Prompt Engineering
Prompt engineering is the process of writing effective instructions for a model, such that it consistently generates content that meets the requirements.
Definition · At a glance · How it works
Definition
Prompt engineering is the process of writing effective instructions for a model, such that it consistently generates content that meets the requirements. With the OpenAI API, a large language model can be used to generate text from a prompt, as one might using ChatGPT. Because the content generated from a model is non-deterministic, prompting to get a desired output is a mix of art and science.
Using message roles is given as an example of a prompt engineering technique that works across models. Even different snapshots of models within the same family could produce different results.
At a glance
Markdown headers and lists can mark distinct sections of a prompt and communicate hierarchy to the model. XML tags can help delineate where one piece of content begins and ends.
How it works
Instructions can be provided to the model with differing levels of authority using the instructions API parameter or message roles. The instructions parameter gives the model high-level instructions on how it should behave while generating a response, including tone, goals, and examples of correct responses. Instructions provided this way take priority over a prompt in the input parameter.
The instructions parameter only applies to the current response generation request. Developer messages are instructions provided by the application developer, prioritized ahead of user messages. User messages are instructions provided by an end user, prioritized behind developer messages.
Messages generated by the model have the assistant role. Developer messages provide the system's rules and business logic, like a function definition. User messages provide inputs and configuration to which the developer message instructions are applied, like arguments to a function.
Few-shot learning lets you steer a large language model toward a new task by including a handful of input/output examples in the prompt, rather than fine-tuning the model. The model implicitly picks up the pattern from those examples and applies it to a prompt. Typically, examples are provided as part of a developer message in an API request.
Adding additional relevant context to the model generation request is sometimes called retrieval-augmented generation (RAG). Within the context they consider during a generation request, models can only handle so much data. This memory limit is called a context window, which is defined in terms of tokens, meaning chunks of data passed in, from text to images.
There are some differences to consider when prompting a reasoning model versus prompting a GPT model. GPT models like gpt-6-astra benefit from precise instructions that explicitly provide the logic and data required to complete the task in the prompt. A reasoning model is like a senior co-worker.
A GPT model is like a junior coworker.
Example
The document gives an example developer message containing examples that show a model how to classify positive or negative customer service reviews. The instructions in that example say to output only a single word with no additional formatting. The document also gives an example of using Markdown and XML tags to construct a developer message with distinct sections and supporting examples. In the code-generation developer message example, the assistant is described as a coding assistant that helps enforce the use of snake case.
Sources
This page is written from the official sources below. Open them to check the original text.
- Official documentationhttps://developers.openai.com/api/docs/guides/prompt-engineeringFetched
Verified ·
This page is written by AI from the official sources above and checked automatically. This site has not tested it. Found a mistake? Tell us.