大家好,我是木易,一个持续关注AI领域的互联网技术产品经理,国内Top2本科,美国Top10 CS研究生,MBA。我坚信AI是普通人变强的“外挂”,所以创建了“AI信息Gap”这个公众号,专注于分享AI全维度知识,包括但不限于AI科普,AI工具测评,AI效率提升,AI行业洞察。关注我,AI之路不迷路,2024我们一起变强。
OpenAI于今年10月的2024开发者大会(OpenAI DevDay 2024)上发布了一个容易令人忽略的更新——提示词自动生成工具。
说这个新功能容易令人忽略,首先是因为它只存在于OpenAI管理后台的Playground中,而并不在大家所熟知的ChatGPT里。其次,即使是在Playground,这个功能也显得很不起眼,因为它仅以一个小图标(icon)出现。
对于这样一个“一键生成提示词”的功能,老粉们应该不陌生,因为Anthropic(推出Claude的那家公司)早在3个月前就已经推出了类似的功能,同样是位于管理后台:Anthropic Console控制台。甚至,Anthropic推出的这个功能还有评估、对比、优化提示词的能力,几乎等同于一个功能完备的提示词管理系统。感兴趣的小伙伴可以看这篇文章:《Claude更新王炸功能:一键生成、评估、优化提示词!》。
OpenAI虽迟但到的这个功能,需要通过登录OpenAI开发者管理后台(ChatGPT账号即可登录)才能体验,具体地址如下。
https://platform.openai.com/playground/
用你的ChatGPT账号登录后,如果你是第一次登录OpenAI开发者管理后台,可能会出现You don't have any API credits
的提醒,这是因为OpenAI加紧了对OpenAI API的管控,改为了“预充值”的模式,之前则是先使用,每月产生账单然后再支付。
API credits则是OpenAI对于充值积分的一种叫法,API credits可以用于所有模型相关的API调用服务,也可以在这个交互式的Playground里快速体验和调试不同模型的能力。换句话说,Playground就是帮助开发者在不编写代码的情况下测试和迭代prompt的一个系统。
如何充值API credits?和开通ChatGPT Plus会员的方法一致,绑定一张境外的银行卡即可进行充值,具体方法可以看:《国内支付宝开通ChatGPT Plus和Claude Pro 2024最新教程!》。
这里值得一提的是,对于API调用不熟悉或者没有强需求的小伙伴,完全不必要充值API credits,ChatGPT Plus已经能满足99%的需求了。后面我会针对API使用方法详细解释和介绍。
Playground Meta-prompts
OpenAI公布了“一键生成提示词”这个功能的系统提示词(Meta Prompt),就是该功能背后的提示词。
from openai import OpenAI
client = OpenAI()
META_PROMPT = """
Given a task description or existing prompt, produce a detailed system prompt to guide a language model in completing the task effectively.
# Guidelines
- Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.
- Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.
- Reasoning Before Conclusions**: Encourage reasoning steps before any conclusions are reached. ATTENTION! If the user provides examples where the reasoning happens afterward, REVERSE the order! NEVER START EXAMPLES WITH CONCLUSIONS!
- Reasoning Order: Call out reasoning portions of the prompt and conclusion parts (specific fields by name). For each, determine the ORDER in which this is done, and whether it needs to be reversed.
- Conclusion, classifications, or results should ALWAYS appear last.
- Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.
- What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.
- Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.
- Formatting: Use markdown features for readability. DO NOT USE ``` CODE BLOCKS UNLESS SPECIFICALLY REQUESTED.
- Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.
- Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.
- Output Format: Explicitly the most appropriate output format, in detail. This should include length and syntax (e.g. short sentence, paragraph, JSON, etc.)
- For tasks outputting well-defined or structured data (classification, JSON, etc.) bias toward outputting a JSON.
- JSON should never be wrapped in code blocks (```) unless explicitly requested.
The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no "---")
[Concise instruction describing the task - this should be the first line in the prompt, no section header]
[Additional details as needed.]
[Optional sections with headings or bullet points for detailed steps.]
# Steps [optional]
[optional: a detailed breakdown of the steps necessary to accomplish the task]
# Output Format
[Specifically call out how the output should be formatted, be it response length, structure e.g. JSON, markdown, etc]
# Examples [optional]
[Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]
[If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]
# Notes [optional]
[optional: edge cases, details, and an area to call or repeat out specific important considerations]
""".strip()
def generate_prompt(task_or_prompt: str):
completion = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": META_PROMPT,
},
{
"role": "user",
"content": "Task, Goal, or Current Prompt:\n" + task_or_prompt,
},
],
)
return completion.choices[0].message.content
这个系统提示词(Meta Prompt)的作用就是指导LLM模型在处理任务时生成高效、符合要求的提示词。它也可以用于改进已有的提示词,但会遵循最小修改原则,确保尽量保留原有提示词的结构和内容。
1. 理解任务:
在生成提示之前,必须充分理解用户提供的任务描述。包括明确任务的目标、要求、限制和预期的输出形式。
2. 最小修改:
如果用户已经提供了现有提示,该Meta Prompt鼓励在简单的情况下进行少量修改。如果提示较复杂,重点是增强清晰度和补充遗漏的内容,而不改变原始结构。
3. 推理先于结论:
提示必须鼓励模型先进行推理,再得出结论。通常来说,推理的部分应该在提示的前半部分,而结论应置于最后。如果用户提供的示例中推理顺序是结论在前,推理在后,则提示会自动将顺序反转,以保持逻辑严密性。
4. 提供高质量示例:
为了帮助用户更好地理解任务,提示应该尽可能提供高质量的示例。这些示例可能使用占位符来表示复杂的元素,以确保提示灵活适应不同的任务要求。
5. 简洁与清晰:
生成的提示必须简洁明了,避免冗长或多余的指示。同时,使用特定的格式(如Markdown)提升可读性,确保提示易于理解和执行。
6. 保留用户内容:
用户输入的任务描述、示例和规则必须尽量保留。如果内容不清楚,可以细分为多个子步骤,但需尽量避免对现有内容的过度改动。
7. 常量处理:
常量(如固定的规则、示例或标准)需要包含在提示中,因为它们不会受到外部的干扰(如提示注入攻击)。这些常量有助于保持提示的一致性和安全性。
8. 输出格式:
明确提示的输出格式非常重要。提示需要根据任务的要求提供详细的输出格式说明,如生成短句、段落或JSON结构等。
9. 输出结构:
这个Meta Prompt要求生成的提示遵循以下结构:
任务描述:简明地描述任务或要求,这是提示的第一部分,不能有标题或其他额外标记。 详细信息:必要时可以添加详细说明,帮助语言模型更好地理解任务背景。 步骤(可选):如果任务复杂,可以使用步骤来分解任务并提供更加明确的指引。 输出格式:要特别指出输出的具体格式要求,比如输出长度、格式(如JSON、Markdown等)。 示例(可选):提供1-3个高质量的示例,用占位符表示复杂的部分,以确保生成提示的灵活性和适用性。 注释(可选):对于边缘情况或特殊要求,可以提供额外的注释,提醒模型在这些情况下的处理方法。
一键生成提示词实战
划重点,这里是支持中文描述的,GPT系列模型对中文还是比较友好的。提示词描述简洁精炼就好。
这里我们还是以“论文阅读助手”为例,让GPT-4o
模型自动生成一个论文阅读助手的提示词。
生成提示词的速度还是比较快的。生成好的提示词会展示在系统提示词框中。
完整的“论文阅读助手”提示词如下。
Act as a paper reading assistant, providing summaries, key points, and interpretations for academic papers.
You will be provided with the title, abstract, and a section or passage from an academic paper.
# Steps
1. **Title and Abstract Understanding**: Summarize the purpose and main ideas presented in the title and abstract.
2. **Key Points Identification**: Extract key points, hypotheses, or methods from the provided section or passage.
3. **Interpretation**: Provide an interpretation or analysis of the significance of these points in the context of the field.
4. **Conclusion**: Summarize the overall findings or implications of the passage.
# Output Format
- **Summary**: A cohesive paragraph summarizing the abstract.
- **Key Points**: A bullet list of key points with brief explanations.
- **Interpretation**: A paragraph interpreting the significance.
- **Conclusion**: A short sentence summarizing the passage's findings.
# Examples
**Input**:
- Title: "The Impact of Quantum Computing on Cryptography"
- Abstract: "This paper explores the potential effects of quantum computing advancements on modern cryptographic techniques..."
- Section: "In recent years, quantum algorithms like Shor's algorithm have demonstrated..."
**Output**:
- **Summary**: This paper investigates how quantum computing may revolutionize current cryptographic methods, highlighting potential vulnerabilities.
- **Key Points**:
- Quantum Algorithms: Discussion of Shor’s algorithm and its effect on encryption.
- Cryptographic Vulnerabilities: Examination of traditional cryptographic weaknesses exposed by quantum technology.
- **Interpretation**: The paper signifies a transformative period in cryptography due to quantum computing, necessitating new secure methods.
- **Conclusion**: Quantum advancements demand a re-evaluation of cryptographic systems.
# Notes
- Ensure technical terminology is preserved but explained for general understanding.
- Consider the specific field or discipline context when interpreting findings.
点评
GPT-4o
生成的这份提示词的属于结构化提示词(Structured Prompt),这样的提示词条理和逻辑清晰,很适合创建AI Agent时使用。首先描述了该系统提示词的角色:a paper reading assistant,以及它的具体功能:providing summaries, key points, and interpretations for academic papers。接着在Steps
这一部分规定AI模型需要做些什么以及按照怎样的步骤来操作。然后在Output Format
规定输出格式,确保每次问答输出的回答在格式上是稳定、统一的。最后,在Examples
给出具体案例,以样例的形式指导模型的输入和输出。
总体来看,这份提示词逻辑清晰、结构紧凑,涵盖了学术阅读助手所需的主要功能。它能够指导模型提取关键信息并进行合理解读,适用于大多数学术论文的分析需求。
结语
OpenAI和Anthropic(Claude)推出的一键生成提示词的功能,对于快速创建一个优质的AI Agent还是非常有帮助的!
精选推荐
国内支付宝开通ChatGPT Plus和Claude Pro 2024最新教程! 『AI保姆级教程』无需手机号!三分钟注册ChatGPT账号!2024年最新教程! 『AI保姆级教程』手把手教你注册Claude账号!建议收藏!
都读到这里了,点个赞鼓励一下吧,小手一赞,年薪百万!😊👍👍👍。关注我,AI之路不迷路,原创技术文章第一时间推送🤖。