石南AI工具導航
登錄
網站目錄

Open AI提示詞生成工具詳解!一鍵生成提示詞!

石南12262024-10-16 23:50:32

OpenAI于今年10月的2024開發者大會(OpenAI DevDay 2024)上發布了一個容易令人忽略的更新——提示詞自動生成工具

說這個新功能容易令人忽略,首先是因為它只存在于OpenAI管理后臺的Playground中,而并不在大家所熟知的ChatGPT里。其次,即使是在Playground,這個功能也顯得很不起眼,因為它僅以一個小圖標(icon)出現。

Open AI提示詞生成工具詳解!一鍵生成提示詞! 第1張

對于這樣一個“一鍵生成提示詞”的功能,老粉們應該不陌生,因為Anthropic(推出Claude的那家公司)早在3個月前就已經推出了類似的功能,同樣是位于管理后臺:Anthropic Console控制臺。甚至,Anthropic推出的這個功能還有評估、對比、優化提示詞的能力,幾乎等同于一個功能完備的提示詞管理系統。

Open AI提示詞生成工具詳解!一鍵生成提示詞! 第2張

Open AI提示詞生成工具詳解!一鍵生成提示詞! 第3張

OpenAI雖遲但到的這個功能,需要通過登錄OpenAI開發者管理后臺(ChatGPT賬號即可登錄)才能體驗,具體地址如下。

https://platform.openai.com/playground/

用你的ChatGPT賬號登錄后,如果你是第一次登錄OpenAI開發者管理后臺,可能會出現You don't have any API credits的提醒,這是因為OpenAI加緊了對OpenAI API的管控,改為了“預充值”的模式,之前則是先使用,每月產生賬單然后再支付。

Open AI提示詞生成工具詳解!一鍵生成提示詞! 第4張

API credits則是OpenAI對于充值積分的一種叫法,API credits可以用于所有模型相關的API調用服務,也可以在這個交互式的Playground里快速體驗和調試不同模型的能力。換句話說,Playground就是幫助開發者在不編寫代碼的情況下測試和迭代prompt的一個系統。

如何充值API credits?和開通ChatGPT Plus會員的方法一致,綁定一張境外的銀行卡即可進行充值。

這里值得一提的是,對于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模型自動生成一個論文閱讀助手的提示詞。

Open AI提示詞生成工具詳解!一鍵生成提示詞! 第5張

生成提示詞的速度還是比較快的。生成好的提示詞會展示在系統提示詞框中。

Open AI提示詞生成工具詳解!一鍵生成提示詞! 第6張

完整的“論文閱讀助手”提示詞如下。

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還是非常有幫助的!


本文鏈接:http://www.tondou.cn/post/1777.html ,轉載需注明文章鏈接來源:http://www.tondou.cn/

分享到:
標簽:Open AIChatGPT
  • 不喜歡(1
本文轉載自互聯網,具體來源未知,或在文章中已說明來源,若有權利人發現,請聯系我們更正。本站尊重原創,轉載文章僅為傳遞更多信息之目的,并不意味著贊同其觀點或證實其內容的真實性。如其他媒體、網站或個人從本網站轉載使用,請保留本站注明的文章來源,并自負版權等法律責任。如有關于文章內容的疑問或投訴,請及時聯系我們。我們轉載此文的目的在于傳遞更多信息,同時也希望找到原作者,感謝各位讀者的支持!

本文鏈接:http://www.tondou.cn/post/1777.html

猜你喜歡

石南

暫無個人介紹

1819 文章
2 頁面
0 評論
589 附件
石南最近發表
最新文章
文章推薦
隨機文章
熱門標簽
側欄廣告位
ChatGPT賬號購買