Prompt Engineering 简明教程

Prompt Engineering - FIND Prompt

FIND 提示使我们可以从 ChatGPT 生成的响应中提取特定信息或执行搜索。通过使用 FIND 指令,我们可以指示语言模型根据特定标准查找并呈现相关详细信息,增强生成的输出的精确性和有用性。

The FIND prompt allows us to extract specific information or perform searches within the generated responses of ChatGPT. By utilizing the FIND directive, we can instruct the language model to find and present relevant details based on specific criteria, enhancing the precision and usefulness of the generated output.

Understanding the FIND Directive

FIND 指令使我们能够指定搜索模式或标准以在 ChatGPT 生成的响应中找到特定信息。它提供了一种方式来从模型的输出中以编程方式搜索和提取相关详细信息。

The FIND directive enables us to specify a search pattern or criteria to locate specific information within the response generated by ChatGPT. It provides a way to programmatically search for and extract relevant details from the model’s output.

用于 FIND 指令的基本 syntax 如下 −

The basic syntax for the FIND directive is as follows −

User: Can you provide a summary of the novel "Pride and Prejudice"?
ChatGPT: "Pride and Prejudice" is a classic novel written by Jane Austen. It explores themes of love, class, and societal expectations. [FIND: themes]

在这个示例中,用户要求总结小说“傲慢与偏见”,ChatGPT 的响应包括 FIND 指令中指定的内容,在本例中是与“主题”相关的信息。

In this example, the user asks for a summary of the novel "Pride and Prejudice," and the response from ChatGPT includes the content specified within the FIND directive, which is the information related to "themes" in this case.

Best Practices for Using the FIND Directive

为了充分利用查找指令,请考虑以下最佳实践:

To make the most of the FIND directive, consider the following best practices −

  1. Be Specific − Clearly define the search pattern or criteria within the FIND directive. This helps ensure that the model locates the desired information accurately.

  2. Contextual Prompts − Incorporate the FIND directive within a contextually rich prompt. By providing relevant context along with the directive, we can guide the model’s understanding and improve the accuracy of the search.

  3. Iterate and Refine − Experiment with different search patterns and criteria to find the most effective way to extract the desired information. Iterate and refine our prompts based on the results obtained.

  4. Combine with Other Techniques − The FIND directive can be used in conjunction with other prompt engineering techniques, such as the INCLUDE directive or COLUMN directive, to further enhance the generated output. Consider combining multiple techniques to achieve our desired results.

Example Application − Python Implementation

我们来探索一个使用查找指令的实际示例和与 ChatGPT 交互的 Python 脚本。

Let’s explore a practical example of using the FIND directive with a Python script that interacts with ChatGPT.

在这个示例中,我们定义了一个 generate_chat_response() 函数,它接受一个提示并使用 OpenAI API 使用 ChatGPT 生成响应。

In this example, we define a function generate_chat_response() that takes a prompt and uses the OpenAI API to generate a response using ChatGPT.

chat_prompt 变量包含用户提示和 ChatGPT 响应,包括查找与“主题”相关的信息的 FIND 指令。

The chat_prompt variable contains the user’s prompt and the ChatGPT response, including the FIND directive to search for information related to "themes."

import openai
# Set your API key here
openai.api_key = 'YOUR_API_KEY'

def generate_chat_response(prompt):
   response = openai.Completion.create(
      engine="text-davinci-003",
      prompt=prompt,
      max_tokens=100,
      temperature=0.7,
      n=1,
      stop=None
   )
   return response

user_prompt = "User: Can you provide a summary of the novel 'Pride and Prejudice'?\n"
chat_prompt = user_prompt + "ChatGPT: 'Pride and Prejudice' is a classic novel written by Jane Austen. It explores themes of love, class, and societal expectations. [FIND: themes]"

response = generate_chat_response(chat_prompt)
print(response)

Output

当我们运行脚本时,我们将收到 ChatGPT 生成的响应,包括基于指定搜索模式提取的详细信息。

When we run the script, we will receive the generated response from ChatGPT, including the extracted details based on the specified search pattern.

The novel follows the five Bennet sisters, Elizabeth, Jane, Lydia, Mary, and Kitty, who are all looking for love and marriage. Elizabeth and her older sister Jane both fall in love with different men, but are faced with obstacles as they must battle society's expectations, their own pride, and the prejudice of others. The novel ultimately ends with the two sisters finding true love and happiness.

Conclusion

在本章中,我们探索了提示工程中查找指令在 ChatGPT 中的力量。通过使用 FIND 指令,我们可以从生成的响应中提取特定信息或执行搜索。

In this chapter, we explored the power of the FIND directive in prompt engineering for ChatGPT. By using the FIND directive, we can extract specific information or perform searches within the generated responses.

我们讨论了 FIND 指令的语法,并提供了有关其使用的最佳实践,包括明确、使用上下文提示、迭代和优化,以及与其他提示工程技术相结合。

We discussed the syntax of the FIND directive and provided best practices for its usage, including being specific, using contextual prompts, iterating and refining, and combining with other prompt engineering techniques.