Prompt Engineering 简明教程

Prompt Engineering - OUTLINE STEPS Prompt

通过使用 OUTLINE STEPS 指令,我们可以利用 ChatGPT 的功能为各种任务或流程生成结构清晰的大纲或分步程序。此技术使我们能够利用 ChatGPT 的知识和组织能力来提供清晰且简洁的指令。

Understanding the OUTLINE STEPS Directive

OUTLINE STEPS 指令允许我们提示 ChatGPT 为完成给定的任务或流程生成结构化的纲要或分步程序。通过在提示中加入 OUTLINE STEPS 指令,我们可以利用 ChatGPT 的组织技能和语言理解力来提供明确的指令。

OUTLINE STEPS 指令的基本 syntax 如下 −

User: Can you outline the steps to bake a cake?
ChatGPT: Absolutely! Here is an outline of the steps to bake a cake:
1. Gather the ingredients and preheat the oven.
2. Mix the dry ingredients together in a bowl.
3. Beat the wet ingredients in a separate bowl.
4. Gradually add the dry ingredients to the wet ingredients while stirring.
5. Pour the batter into a greased baking pan.
6. Bake in the preheated oven for the specified time.
7. Remove from the oven and let it cool before serving.

在这个示例中,用户请求烘焙蛋糕的步骤大纲。来自 ChatGPT 的响应包括一个结构化大纲,其中包含根据给定的提示生成的详细步骤。

Best Practices for Using the OUTLINE STEPS Directive

为了充分利用 OUTLINE STEPS 指令,我们来考虑以下最佳实践 −

  1. Clearly Define the Task or Process − 对我们想要大纲的任务或流程,提供一个清晰且简洁的说明。这有助于 ChatGPT 理解上下并生成相关的步骤。

  2. Use Action Verbs − 提示 ChatGPT 在步骤中使用动作动词以提供明确的说明。这可确保每一步都可操作,并且容易理解。

  3. Break Down Complex Tasks − 如果任务或过程很复杂,提示 ChatGPT 将其分解为更小、更易于管理的步骤。这有助于用户轻松地遵循说明。

  4. Include Additional Details − 鼓励 ChatGPT 为每个步骤包括必需的详细信息或具体要求。这样可确保该说明全面,并涵盖任务或过程的所有重要方面。

Example Application − Python Implementation

让我们探索一个使用 OUTLINE STEPS 指令与 Python 脚本交互的实际示例,该脚本与 ChatGPT 交互。

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 outline the steps to assemble a piece of furniture?\n"

chat_prompt = user_prompt + "ChatGPT: [OUTLINE STEPS: assemble a piece of furniture]"

response = generate_chat_response(chat_prompt)
print(response)

在这个示例中,我们定义了一个函数 generate_chat_response(),它接收一个提示并使用 OpenAI API 来生成一个使用 ChatGPT 生成的响应。chat_prompt 变量包含用户的提示和 ChatGPT 响应,包括 OUTLINE STEPS 指令,用于概述组装家具的步骤。

Output

当我们运行脚本时,我们会收到来自 ChatGPT 的生成的响应,包括在 OUTLINE STEPS 指令中指定的具有分步说明的结构化概述。

本处用户提示是“你能概述组装一件家具的步骤吗?”,而 ChatGPT 将响应内容如下:

1. Gather all necessary tools and parts.
2. Read through the instructions carefully.
3. Secure the frame and/or base of the furniture.
4. Attach the seat, back, and arms (if applicable).
5. Add any additional features such as cushions, drawers, etc.
6. Check all fasteners and screws for tightness.
7. Clean and inspect the finished product.

Conclusion

在本章中,我们探索了 ChatGPT 提示工程中的 OUTLINE STEPS 指令。使用 OUTLINE STEPS 指令,我们可以提示 ChatGPT 为各种任务或流程生成结构化概述或分步程序。