Liang shared a prompt guide written by OpenAI in the group. The original text is quite long, so based on the principle of Occam's Razor, I have summarized the key points that are helpful to me:
To view the unedited original text, please visit the OpenAI official website https://platform.openai.com/docs/guides/prompt-engineering/.
Core content of the article: Writing effective prompts mainly includes six key points:
1. Clear instructions
1.1 Provide more details
Poor example | Better example |
---|---|
How to add numbers in Excel? | How to calculate the total sum of a row of dollar amounts in Excel? I hope to automatically calculate each row in the entire table, and finally display all the totals in a column named "Total". |
Who is the president? | Who was the president of Mexico in 2021? How frequent are elections in Mexico? |
1.2 Use specific roles
Document.
Write a thank-you letter to express gratitude to my steel bolt supplier for completing delivery promptly and within a short time, which allowed us to deliver an important order on time.
1.3 Use delimiters to clearly distinguish different parts of the input
You will receive two articles on the same topic (separated by XML tags). First, summarize the arguments of each article. Then, indicate which article's argument is more persuasive and explain why.
Insert the second article here
1.4 Clearly define the steps required to complete the task
Use the following step-by-step guide to respond to user input.
The user will provide text in triple quotes. Summarize this text in one sentence and add the prefix "Summary:".
Translate the summary from Step 1 into Spanish, and add the prefix "Translation:".
"""Insert text here"""
1.5 Provide examples ("few-shot")
in a consistent
Teach me about the concept of patience.
The rivers that carve the deepest valleys come from gentle springs; the grandest symphonies start with a single note; the most complex tapestries begin with a solitary thread.
Teach me about the ocean.
1.6 Specify the required output length
to summarize the text within the triple quotes.
"""Insert text here"""
Optimized article:
2. Provide reference text
2.1 Guide the model to answer using the reference text
Use triple quotes to separate articles to answer questions. If the answer cannot be found in the article, please write "unable to find the answer".
"""< Insert triple-quoted article here >"""
Question: < Insert question here >
2.2 Guide the model to answer questions by referencing the provided text
, and quote the paragraph from the document that was used to answer the question. If there is not enough information in the document to answer the question, simply write: "Insufficient information." If an answer to the question is provided, a quotation must be attached. Use the following format to quote relevant paragraphs ({"citation": …}).
"""< Insert the document here >"""
Question: < Insert the question here >
3. Break down complex tasks into simpler subtasks
3.1 Use intent classification to identify the most relevant instructions for user queries
3.2 For applications requiring long conversations, summarize or filter previous dialogues
Method:
a. Summarize the previous rounds of the dialogue. b. Use embedding-based search to achieve efficient knowledge retrieval.
3.3 Segment-wise summarization of long documents and recursive construction of complete abstracts
Steps:
Step 1. Summarize each part of the document through a series of queries. Step 2. Section summaries can be concatenated and summarized to form a summary of summaries. Step 3. Recursively perform Step 2 until the entire document is summarized.
4. Give the model time to "think"
4.1 Guide the model to find its own solutions before rushing to conclusions
A direct answer would be incorrect:
If you calculate the answer yourself, you'll know that User is wrong:
4.2 Use internal monologues or a series of queries to explore the reasoning process of the model
4.3 Ask the model if it has omitted anything in the previous process
When the source document is large, the model may stop prematurely and fail to list all relevant excerpts. You can prompt the model through subsequent queries to find any excerpts it may have missed earlier.
You will receive a document separated by triple quotes. Your task is to select excerpts relevant to the following question: "What major paradigm shifts have occurred in the history of artificial intelligence?" Ensure that the excerpts include all relevant background information needed to explain them— in other words, do not extract small snippets that lack important context. Provide the output in JSON format as follows:
[{"excerpt": "..."}, {"excerpt": "..."}]
"""< Insert document here >"""
[{ "Excerpt": "Model writes excerpt here" }, {"Excerpt": "Model writes another excerpt here"}]
Please make sure not to repeat excerpts. Also ensure that the excerpts contain all relevant background information necessary to explain them.
5. Use external tools
5.1 Use embedding-based search to implement efficient knowledge retrieval
Use VectorDB - https://cookbook.openai.com/examples/vector_databases/readme
5.2 Use code execution for more accurate calculations or call external APIs
. Use this feature to perform calculations.
Find all the real roots of the following polynomial: 3
5.3 Granting the model access to specific functions
You can refer to Function Call - https://platform.openai.com/docs/guides/function-calling
6. Systematically test changes
6.1 Use LLM evaluation frameworks
You can refer to OpenAI Evals - https://github.com/openai/evals
6.2 Evaluate model output with reference to a gold standard answer
If we know that the correct answer to a question should involve a set of specific known facts, we can use model queries to calculate how many required facts are included in the answer.
👆This part is somewhat complex and may not be commonly needed. You can check the relevant documentation at https://platform.openai.com/playground/p/default-model-based-eval-3?mode=chat.
More examples can be found at: https://platform.openai.com/examples