Prompt Engineering 简明教程
Prompt Engineering - CREATE A LIST Prompt
使用“创建列表”提示,我们可以利用 ChatGPT 的强大功能来生成经过整理的项目、建议或建议列表。
The CREATE A LIST prompt allows us to harness the power of ChatGPT to generate curated lists of items, recommendations, or suggestions.
通过使用 CREATE A LIST 指令,我们可以提示 ChatGPT 以列表的形式提供组织和结构化的响应。
By utilizing the CREATE A LIST directive, we can prompt ChatGPT to provide organized and structured responses in the form of lists.
Understanding the CREATE A LIST Directive
CREATE A LIST 指令使我们能够指示 ChatGPT 根据特定标准或提示生成列表。通过在提示中合并 CREATE A LIST 指令,我们可以利用 ChatGPT 的知识和语言理解能力来创建经过筛选的列表。
The CREATE A LIST directive enables us to instruct ChatGPT to generate lists based on specific criteria or prompts. By incorporating the CREATE A LIST directive in our prompts, we can leverage ChatGPT’s knowledge and language understanding to create curated lists.
CREATE A LIST 指令的基本 syntax 如下:
The basic syntax for the CREATE A LIST directive is as follows −
User: Can you create a list of must-read books?
ChatGPT: Certainly! Here are some must-read books:
- "To Kill a Mockingbird" by Harper Lee
- "1984" by George Orwell
- "Pride and Prejudice" by Jane Austen
- "The Great Gatsby" by F. Scott Fitzgerald
在这个示例中,用户请求了一份必读书籍清单。ChatGPT 的响应包括一个基于给定提示的经过筛选的书籍清单。
In this example, the user requests a list of must-read books. The response from ChatGPT includes a curated list of books based on the given prompt.
Best Practices for Using the CREATE A LIST Directive
为了充分利用 CREATE A LIST 指令,让我们考虑以下最佳实践:
To make the most of the CREATE A LIST directive, let’s consider the following best practices −
-
Provide Clear and Specific Prompts − Clearly state the criteria or topic for which we need a list. The more specific and detailed the prompt, the more focused and relevant the generated list will be.
-
Organize the List − Format the response generated by ChatGPT as a well-structured list. Use bullet points, numbers, or other appropriate formatting to present the items in an organized and readable manner.
-
Contextualize the List − Incorporate relevant context or specific requirements within the prompt to guide the generation of the list. This helps ensure that the list aligns with the specific criteria or constraints of the given topic.
-
Iterate and Refine − Experiment with different prompts and iterate on them to generate diverse and comprehensive lists. Adjust the prompts based on the quality and relevance of the generated lists.
Example Application − Python Implementation
让我们来探索一个使用 CREATE A LIST 指令与 ChatGPT 交互的 Python 脚本的实际示例。
Let’s explore a practical example of using the CREATE A LIST 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 响应,包括 CREATE A LIST 指令以创建必看电影列表。
The chat_prompt variable contains the user’s prompt and the ChatGPT response, including the CREATE A LIST directive to create a list of must-watch movies.
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 create a list of must-watch movies?\n"
chat_prompt = user_prompt + "ChatGPT: [CREATE A LIST: must-watch movies]"
response = generate_chat_response(chat_prompt)
print(response)
Output
当我们运行脚本时,我们将收到 ChatGPT 生成的响应,包括 CREATE A LIST 指令中指定的经过筛选的电影列表。
When we run the script, we will receive the generated response from ChatGPT, including the curated list of movies specified within the CREATE A LIST directive.
1. The Godfather (1972)
2. The Shawshank Redemption (1994)
3. The Dark Knight (2008)
4. Schindler's List (1993)
5. Pulp Fiction (1994)
6. The Lord of the Rings Trilogy (2001-2003)
7. The Good, the Bad and the Ugly (1966)
8. 12 Angry Men (1957)
Conclusion
在本章中,我们探索了用于 ChatGPT 提示工程的创建列表指令。通过利用创建列表指令,我们可以利用 ChatGPT 生成整理好的商品、建议或提示列表。
In this chapter, we explored the CREATE A LIST directive in prompt engineering for ChatGPT. By utilizing the CREATE A LIST directive, we can leverage ChatGPT to generate curated lists of items, recommendations, or suggestions.