How to get the most out of AI models like GPT-4 with practical prompt engineering techniques that improve response accuracy and relevance, from OpenAI’s guides.
How to get the most out of AI models like GPT-4 with practical prompt engineering techniques that improve response accuracy and relevance, from OpenAI’s guides.
来自OpenAI的提示词技巧
Use Case: Enhancing the effectiveness and accuracy of AI responses through strategic prompt engineering.
This guide outlines various strategies and tactics to optimize prompt engineering for large language models such as GPT-4. It includes tips on writing clear instructions, providing reference texts, splitting complex tasks into simpler ones, and using external tools to improve model performance. By applying these techniques, users can significantly enhance the quality and relevance of AI-generated responses.
Bear’s take
Bear: Prompt engineering is like fine-tuning a musical instrument – with the right adjustments, you can make it sing beautifully. One time, I was working on a project and needed a summary of a complex report. By breaking down the task into smaller steps and providing clear examples, I got a concise and accurate summary that saved me hours of work.
What you’ll learn
From this guide, you'll learn how to craft prompts that maximize the capabilities of AI models like GPT-4. You'll discover strategies for writing clear and detailed instructions, specifying the desired length and format of outputs, and using reference texts to guide the AI. The guide also covers how to split complex tasks into simpler subtasks, allowing the AI to handle them more effectively. Additionally, you'll explore the use of external tools to complement the AI's abilities, such as using code execution for precise calculations. By the end, you'll be equipped with practical tactics to enhance the accuracy and relevance of AI responses, making these tools more useful for your everyday tasks.
Key points
Write Clear Instructions: Include specific details and context in your prompts.
Provide Reference Text: Supply relevant information to guide the AI's responses.
Split Complex Tasks: Break down large tasks into manageable subtasks.
Specify Desired Output: Indicate the length and format of the response you need.
Use External Tools: Leverage tools like code execution for precise calculations.
Next step
Start experimenting with the tactics discussed in the guide.
Practice creating different types of prompts to see which techniques yield the best results.
Explore the OpenAI Cookbook and other resources for more advanced prompting strategies.
Links or resource
Six Prompting Strategies
1. Write Clear Instructions
These models can’t read your mind. If outputs are too long, ask for brief replies. If outputs are too simple, ask for expert-level writing. If you dislike the format, demonstrate the format you’d like to see. The less the model has to guess at what you want, the more likely you’ll get it.
Tactics:
Include details in your query to get more relevant answers
Ask the model to adopt a persona
Use delimiters to clearly indicate distinct parts of the input
Specify the steps required to complete a task
Provide examples
Specify the desired length of the output
2. Provide Reference Text
Language models can confidently invent fake answers, especially when asked about esoteric topics or for citations and URLs. In the same way that a sheet of notes can help a student do better on a test, providing reference text to these models can help in answering with fewer fabrications.
Tactics:
Instruct the model to answer using a reference text
Instruct the model to answer with citations from a reference text
3. Split Complex Tasks
Just as it is good practice in software engineering to decompose a complex system into a set of modular components, the same is true of tasks submitted to a language model. Complex tasks tend to have higher error rates than simpler tasks. Furthermore, complex tasks can often be re-defined as a workflow of simpler tasks in which the outputs of earlier tasks are used to construct the inputs to later tasks.
Tactics:
Use intent classification to identify the most relevant instructions for a user query
For dialogue applications that require very long conversations, summarize or filter previous dialogue
Summarize long documents piecewise and construct a full summary recursively
4. Give the Model Time to “Think”
If asked to multiply 17 by 28, you might not know it instantly, but can still work it out with time. Similarly, models make more reasoning errors when trying to answer right away, rather than taking time to work out an answer. Asking for a “chain of thought” before an answer can help the model reason its way toward correct answers more reliably.
Tactics:
Instruct the model to work out its own solution before rushing to a conclusion
Use inner monologue or a sequence of queries to hide the model’s reasoning process
Ask the model if it missed anything on previous passes
5. Use External Tools
Compensate for the weaknesses of the model by feeding it the outputs of other tools. For example, a text retrieval system (sometimes called RAG or retrieval augmented generation) can tell the model about relevant documents. A code execution engine like OpenAI’s Code Interpreter can help the model do math and run code. If a task can be done more reliably or efficiently by a tool rather than by a language model, offload it to get the best of both.
Tactics:
Use embeddings-based search to implement efficient knowledge retrieval
Use code execution to perform more accurate calculations or call external APIs
Give the model access to specific functions
6. Test Changes Systematically
Improving performance is easier if you can measure it. In some cases a modification to a prompt will achieve better performance on a few isolated examples but lead to worse overall performance on a more representative set of examples. Therefore to be sure that a change is net positive to performance it may be necessary to define a comprehensive test suite (also known as an “eval”).
Tactic:
Evaluate model outputs with reference to gold-standard answers
Discover how psychological techniques like priming and anchoring can significantly influence AI responses, revealing the importance of human oversight.