General Tips for Designing Prompts

General Tips for Designing Prompts

設計提示的一般建議

Here are some tips to keep in mind while you are designing your prompts:

以下是在設計提示時需要記住的一些提示:

Start Simple

開始簡單

As you get started with designing prompts, you should keep in mind that it is really an iterative process that requires a lot of experimentation to get optimal results. Using a simple playground like OpenAI or Cohere's is a good starting point.

當你開始設計提示時,應該牢記這是一個需要大量實驗和迭代的過程,以獲得最佳結果。像 OpenAI 或 Cohere 這樣的簡單遊戲場是一個很好的起點。

You can start with simple prompts and keep adding more elements and context as you aim for better results. Versioning your prompt along the way is vital for this reason. As we read the guide you will see many examples where specificity, simplicity, and conciseness will often give you better results.

你可以從簡單的提示開始,隨著你追求更好的結果,不斷新增更多的元素和上下文。因此,沿途對你的提示進行版本控制非常重要。當你閱讀本指南時,你會看到許多例子,其中特定性、簡潔性和簡明性通常會給你帶來更好的結果。

When you have a big task that involves many different subtasks, you can try to break down the task into simpler subtasks and keep building up as you get better results. This avoids adding too much complexity to the prompt design process at the beginning.

當你有一個涉及許多不同子任務的大任務時,你可以嘗試將任務分解為更簡單的子任務,並隨著獲得更好的結果而不斷建構。這可以避免在開始時將太多複雜性新增到提示設計過程中。

The Instruction

指令

You can design effective prompts for various simple tasks by using commands to instruct the model what you want to achieve such as "Write", "Classify", "Summarize", "Translate", "Order", etc.

您可以使用命令來指示模型實現您想要的目標,例如“寫作”,“分類”,“總結”,“翻譯”,“排序”等,從而為各種簡單任務設計有效的提示。

Keep in mind that you also need to experiment a lot to see what works best. Try different instructions with different keywords, contexts, and data and see what works best for your particular use case and task. Usually, the more specific and relevant the context is to the task you are trying to perform, the better. We will touch on the importance of sampling and adding more context in the upcoming guides.

請記住,您還需要進行大量實驗,以檢視哪種方法最有效。嘗試使用不同的指令、關鍵詞、上下文和資料,看看哪種方法最適合您的特定使用案例和任務。通常,上下文越具體和相關,對您要執行的任務越有幫助。在即將推出的指南中,我們將談到抽樣和新增更多上下文的重要性。

Others recommend that instructions are placed at the beginning of the prompt. It's also recommended that some clear separator like "###" is used to separate the instruction and context.

其他人建議將指示放在提示的開頭。同時建議使用一些清晰的分隔符,例如“###”,來區分指示和上下文。

For instance:

例如:

Prompt:

提示:

### Instruction ###
Translate the text below to Spanish:

Text: "hello!"

Output:

輸出:

¡Hola!

Specificity

特異性

Be very specific about the instruction and task you want the model to perform. The more descriptive and detailed the prompt is, the better the results. This is particularly important when you have a desired outcome or style of generation you are seeking. There aren't specific tokens or keywords that lead to better results. It's more important to have a good format and descriptive prompt. In fact, providing examples in the prompt is very effective to get desired output in specific formats.

非常具體地說明您想要模型執行的指令和任務。提示越詳細和詳盡,結果就越好。當您有所期望的產生結果或風格時,這一點尤其重要。沒有特定的標記或關鍵字可以帶來更好的結果。擁有良好的格式和詳細的提示更為重要。事實上,在提示中提供示範非常有效,可以獲得特定格式的期望輸出。

When designing prompts you should also keep in mind the length of the prompt as there are limitations regarding how long this can be. Thinking about how specific and detailed you should be is something to consider. Including too many unnecessary details is not necessarily a good approach. The details should be relevant and contribute to the task at hand. This is something you will need to experiment with a lot. We encourage a lot of experimentation and iteration to optimize prompts for your applications.

在設計提示時,您還應考慮提示的長度,因為提示的長度有限制。考慮提示的具體和詳細程度是需要考慮的事情。包含過多不必要的細節並不一定是一個好的方法。細節應該是相關的,並有助於完成任務。這是您需要大量嘗試的事情。我們鼓勵大量實驗和迭代,以優化您的應用程序的提示。

As an example, let's try a simple prompt to extract specific information from a piece of text.

作為一個例子,讓我們嘗試一個簡單的提示,從一段文字中提取特定的資訊。

Prompt:

提示:

Extract the name of places in the following text.

Desired format:
Place: <comma_separated_list_of_company_names>

Input: "Although these developments are encouraging to researchers, much is still a mystery. “We often have a black box between the brain and the effect we see in the periphery,” says Henrique Veiga-Fernandes, a neuroimmunologist at the Champalimaud Centre for the Unknown in Lisbon. “If we want to use it in the therapeutic context, we actually need to understand the mechanism.""

Output:

輸出:

Place: Champalimaud Centre for the Unknown, Lisbon

Input text is obtained from this Nature article (opens in a new tab).

輸入文字來自於這篇自然期刊文章 (opens in a new tab)

Avoid Impreciseness

避免不精確

Given the tips above about being detailed and improving format, it's easy to fall into the trap of wanting to be too clever about prompts and potentially creating imprecise descriptions. It's often better to be specific and direct. The analogy here is very similar to effective communication -- the more direct, the more effective the message gets across.

鑒於上述有關詳細和改進格式的提示,很容易陷入想要在提示方面過於聰明並可能建立不精確描述的陷阱。更具體和直接往往更好。這裡的類比非常類似於有效的溝通 - 越直接,資訊傳達就越有效。

For example, you might be interested in learning the concept of prompt engineering. You might try something like:

例如,您可能有興趣學習提示工程的概念。您可以嘗試類似以下的內容:

Explain the concept prompt engineering. Keep the explanation short, only a few sentences, and don't be too descriptive.

It's not clear from the prompt above how many sentences to use and what style. You might still somewhat get good responses with the above prompts but the better prompt would be one that is very specific, concise, and to the point. Something like:

上面的提示不清楚要使用多少句子和什麼風格。您可能仍然可以使用上面的提示獲得一些好的回應,但更好的提示應該是非常具體、簡潔和直接的。例如:

Use 2-3 sentences to explain the concept of prompt engineering to a high school student.

To do or not to do?

做還是不做?

Another common tip when designing prompts is to avoid saying what not to do but say what to do instead. This encourages more specificity and focuses on the details that lead to good responses from the model.

另一個常見的提示是在設計提示時避免說什麼不要做,而是說應該做什麼。這鼓勵更具體化,並關注導致模型良好響應的細節。

Here is an example of a movie recommendation chatbot failing at exactly what I don't want it to do because of how I wrote the instruction -- focusing on what not to do.

這裡是一個電影推薦聊天機器人的例子,它因為我寫的指示太著重於不要做什麼而失敗了。

Prompt:

提示:

The following is an agent that recommends movies to a customer. DO NOT ASK FOR INTERESTS. DO NOT ASK FOR PERSONAL INFORMATION.

Customer: Please recommend a movie based on my interests.
Agent:

Output:

輸出:

Sure, I can recommend a movie based on your interests. What kind of movie would you like to watch? Do you prefer action, comedy, romance, or something else?

Here is a better prompt:

這裡有一個更好的提示:

Prompt:

提示:

The following is an agent that recommends movies to a customer. The agent is responsible to recommend a movie from the top global trending movies. It should refrain from asking users for their preferences and avoid asking for personal information. If the agent doesn't have a movie to recommend, it should respond "Sorry, couldn't find a movie to recommend today.".

Customer: Please recommend a movie based on my interests.
Agent:

Output:

輸出:

Sorry, I don't have any information about your interests. However, here's a list of the top global trending movies right now: [list of movies]. I hope you find something you like!

Some of the examples above were adopted from the "Best practices for prompt engineering with OpenAI API" article. (opens in a new tab)

一些以上的例子是從「使用 OpenAI API 進行提示工程的最佳實踐 (opens in a new tab)」文章中採用的。