OpenAI Official Prompt Engineering Guide
Original address: https://platform.openai.com/docs/guides/prompt-engineering
This guide shares how to more effectively use large language models like GPT-4 (sometimes called GPT models) to achieve better results. The methods introduced can be combined with each other to exert greater effects. We encourage you to experiment and find the techniques that work best for you.
Currently, some examples demonstrated here only apply to the most advanced model gpt-4. In general, if the model you try fails to succeed in a task and a more advanced model is available, you may try again with a more advanced model.
In addition, you can view some example prompts to understand what our models can do:
Prompt examples
Browse these examples to discover the potential of GPT models.
Six Strategies to Help You Achieve Better Results
Write Clear Instructions
These models are not mind readers and cannot guess your thoughts. If the model’s output is too long, you can ask it to answer briefly. If the model’s output is too simple, you can request writing at a more professional level. If you are dissatisfied with the output format, you can directly show the expected format. It is best to make the model not need to guess what you want, so that you are most likely to get the desired results.
- Tips:
Provide Reference Texts
If you have specific materials or examples on the topic you want to write about, show them to the AI so that it can provide more accurate and relevant content. Language models may create false answers, especially when asked about specific topics or required to cite references and URLs. Providing reference texts can help the model provide more accurate answers.
- Tips:
"""<Insert document here>"""
Question: <Insert question here>
- Ask the model to cite content from reference texts when answering. For example, you will be given a document separated by triple quotes and a question. Your task is to answer the question using only the provided document and cite the paragraphs used to answer the question. If the document does not contain the information needed to answer the question, simply write: “Insufficient information”. If the answer to the question is provided, it must be accompanied by a citation note. Use the following format to cite relevant paragraphs ({“citation”: …}):
"""<Insert document here>"""
Question: <Insert question here>
Break Complex Tasks into Simple Subtasks
If you have a complex topic to write about, try to divide it into several small parts. For example, first write a section on the background of the topic, and then write a section on the main points. Just as in software engineering, complex systems are decomposed into modular components, the same approach should be taken when submitting tasks to language models. Complex tasks generally have higher error rates than simple tasks. Complex tasks can often be redefined as a workflow of a series of simple tasks.
- Tips:
Give the Model Time to “Think”
Models may make more reasoning errors when answering questions immediately. Asking the model to engage in a “chain of thought” before giving an answer can help the model reason out the correct answer more reliably.
- Tips:
Use External Tools
Sometimes, combining AI with other tools (such as data search tools) can achieve better results. Use the output of other tools to compensate for the model’s shortcomings. For example, a text retrieval system can provide the model with relevant document information, and a code execution engine can help the model perform mathematical calculations and run code.
- Tips:
Test and Adjust
Try different instructions and methods to see which one works best, then adjust based on the results. “Evaluating model output using golden standard answers” is an effective method to ensure the quality of AI model responses.
- Specific Operations: This strategy is particularly suitable for scenarios requiring precise and detailed information, such as science, technology, or academic research. By comparing with golden standard answers, the output quality of AI models can be effectively monitored and improved.