OpenAI Prompt generation - 生成和优化Prompt的Prompt

devtools/2024/10/19 11:36:10/

OpenAI Prompt generation - 生成和优化Prompt的Prompt

从头开始创建 Prompt 可能很耗时,所以快速生成 Prompt 可以帮助我们提高效率。

下面是 OpenAI 提供的协助生成 Prompt 的 Prompt。

from openai import OpenAIclient = 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

参考资料:


http://www.ppmy.cn/devtools/126992.html

相关文章

SaaS医疗云HIS平台源码,java二甲医院云信息系统源码,整合HIS、EMR、LIS系统,支持二次开发。

SaaS模式java版云HIS平台源码,二甲医院云HIS系统源代码,全套开发文档和产品文档,助力快速熟悉和掌握源码。 云HIS系统概述 基层医院云信息系统(云HIS)是基于云计算技术的一种现代化医院管理系统,整合HIS、…

C++算法练习-day7——707.设计链表

题目来源:. - 力扣(LeetCode) 题目思路分析 在编程中,链表是一种常见的数据结构,用于存储一系列元素,但与数组不同,链表中的元素在内存中不必连续存储。每个元素(称为节点&#xf…

MyBatis 配置详解

在项目中经常会用到 mybatis 相关的一些配置,而在启动类项目工程中,一般会把 mybatis 配置文件单独写到 mybatis,yml 中,如下简单介绍下常用的 mybatis 配置 mybatis:configuration:call-setters-on-nulls: truemap-underscore-to-camel-case…

2024年十大前沿图像分割模型汇总:工作机制、优点和缺点介绍

《博主简介》 小伙伴们好,我是阿旭。专注于人工智能、AIGC、python、计算机视觉相关分享研究。 ✌更多学习资源,可关注公-仲-hao:【阿旭算法与机器学习】,共同学习交流~ 👍感谢小伙伴们点赞、关注! 《------往期经典推…

web前端面试中拍摄的真实vue面试题

发一波web前端面试题,真实拍摄。最最最最最简单的vue面试题了。 image image image 如果以上都不会,那么vue面试基本都是凉了,想彻底学习一下,我这里在之前录制过一套vue面试题的视频教程。 视频地址:https://www.3moo…

一图解千言,了解常见的流程图类型及其作用

在企业管理、软件研发过程中,经常会需要进行各种业务流程梳理,而流程图就是梳理业务时必要的手段,同时也是梳理的产出。但在不同的情况下适用的流程图又不尽相同。 本文我们就一起来总结一下8 种最常见的流程图类型 数据流程图 数据流程图&…

windows安装VMware虚拟机 在虚拟机中安装Centos系统

文章目录 安装虚拟机Centos7.5 软硬件安装安装Centos所需的硬件配置处理器与内核 安装虚拟机 Centos7.5 软硬件安装 安装Centos所需的硬件 配置处理器与内核 一个CPU可以有多个内核 此处可以看出该电脑一个处理器,四个内核。配置虚拟器的原则是不能超过总数的一半…

30 天 Python 3 学习计划

30 天 Python 3 学习计划 https://www.runoob.com/python3/python3-tutorial.html 1. Python3 基础语法 2. Python3 基本数据类型 3. Python3 数据类型转换 4. Python3 解释器 5. Python3 注释 6. Python3 运算符 7. Python3 数字(Number) 8. Python3 字符串 …