OpenAI持续open,meta prompt开源

目录

前言

提示(Prompts)

Playground中的元提示借鉴了OpenAI提示工程最佳实践和用户的实际经验。

模式(Schemas)

自描述模式 -元模式。

虽然OpenAI目前使用元提示和模式,但将来可能会集成更先进的技术,如DSPy


拉到文末,资源福利获取

前言

OpenAI在开源多智能体(multi-agent)框架Swarm的同时,也将Prompt方面的一些实践也开放出来

OpenAI终于open了,Swarm开源来袭~

从头开始创建提示和架构可能非常耗时,因此OpenAI此次开源的prompt实践可以帮助快速入门:

  • 提示:使用结合最佳实践的元提示来生成或改进提示。

  • 模式:使用生成有效 JSON 和函数语法的元模式。

提示(Prompts)

元提示会指示模型根据任务描述创建一个好的提示或改进现有的提示。

Playground中的元提示借鉴了OpenAI提示工程最佳实践和用户的实际经验。

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

模式(Schemas

结构化输出模式和函数模式本身就是 JSON 对象,因此利用结构化输出来生成它们。

这需要为所需的输出定义一个模式,在这种场景,它本身就是一个模式。

为此,需要一个

自描述模式 -元模式。

每个元模式都有一个相应的提示,其中包含少量样本。

from openai import OpenAIimport json
client = OpenAI()
META_SCHEMA = {  "name": "metaschema",  "schema": {    "type": "object",    "properties": {      "name": {        "type": "string",        "description": "The name of the schema"      },      "type": {        "type": "string",        "enum": [          "object",          "array",          "string",          "number",          "boolean",          "null"        ]      },      "properties": {        "type": "object",        "additionalProperties": {          "$ref": "#/$defs/schema_definition"        }      },      "items": {        "anyOf": [          {            "$ref": "#/$defs/schema_definition"          },          {            "type": "array",            "items": {              "$ref": "#/$defs/schema_definition"            }          }        ]      },      "required": {        "type": "array",        "items": {          "type": "string"        }      },      "additionalProperties": {        "type": "boolean"      }    },    "required": [      "type"    ],    "additionalProperties": False,    "if": {      "properties": {        "type": {          "const": "object"        }      }    },    "then": {      "required": [        "properties"      ]    },    "$defs": {      "schema_definition": {        "type": "object",        "properties": {          "type": {            "type": "string",            "enum": [              "object",              "array",              "string",              "number",              "boolean",              "null"            ]          },          "properties": {            "type": "object",            "additionalProperties": {              "$ref": "#/$defs/schema_definition"            }          },          "items": {            "anyOf": [              {                "$ref": "#/$defs/schema_definition"              },              {                "type": "array",                "items": {                  "$ref": "#/$defs/schema_definition"                }              }            ]          },          "required": {            "type": "array",            "items": {              "type": "string"            }          },          "additionalProperties": {            "type": "boolean"          }        },        "required": [          "type"        ],        "additionalProperties": False,        "if": {          "properties": {            "type": {              "const": "object"            }          }        },        "then": {          "required": [            "properties"          ]        }      }    }  }}
META_PROMPT = """# InstructionsReturn a valid schema for the described JSON.
You must also make sure:- all fields in an object are set as required- I REPEAT, ALL FIELDS MUST BE MARKED AS REQUIRED- all objects must have additionalProperties set to false    - because of this, some cases like "attributes" or "metadata" properties that would normally allow additional properties should instead have a fixed set of properties- all objects must have properties defined- field order matters. any form of "thinking" or "explanation" should come before the conclusion- $defs must be defined under the schema param
Notable keywords NOT supported include:- For strings: minLength, maxLength, pattern, format- For numbers: minimum, maximum, multipleOf- For objects: patternProperties, unevaluatedProperties, propertyNames, minProperties, maxProperties- For arrays: unevaluatedItems, contains, minContains, maxContains, minItems, maxItems, uniqueItems
Other notes:- definitions and recursion are supported- only if necessary to include references e.g. "$defs", it must be inside the "schema" object
# ExamplesInput: Generate a math reasoning schema with steps and a final answer.Output: {    "name": "math_reasoning",    "type": "object",    "properties": {        "steps": {            "type": "array",            "description": "A sequence of steps involved in solving the math problem.",            "items": {                "type": "object",                "properties": {                    "explanation": {                        "type": "string",                        "description": "Description of the reasoning or method used in this step."                    },                    "output": {                        "type": "string",                        "description": "Result or outcome of this specific step."                    }                },                "required": [                    "explanation",                    "output"                ],                "additionalProperties": false            }        },        "final_answer": {            "type": "string",            "description": "The final solution or answer to the math problem."        }    },    "required": [        "steps",        "final_answer"    ],    "additionalProperties": false}
Input: Give me a linked listOutput: {    "name": "linked_list",    "type": "object",    "properties": {        "linked_list": {            "$ref": "#/$defs/linked_list_node",            "description": "The head node of the linked list."        }    },    "$defs": {        "linked_list_node": {            "type": "object",            "description": "Defines a node in a singly linked list.",            "properties": {                "value": {                    "type": "number",                    "description": "The value stored in this node."                },                "next": {                    "anyOf": [                        {                            "$ref": "#/$defs/linked_list_node"                        },                        {                            "type": "null"                        }                    ],                    "description": "Reference to the next node; null if it is the last node."                }            },            "required": [                "value",                "next"            ],            "additionalProperties": false        }    },    "required": [        "linked_list"    ],    "additionalProperties": false}
Input: Dynamically generated UIOutput: {    "name": "ui",    "type": "object",    "properties": {        "type": {            "type": "string",            "description": "The type of the UI component",            "enum": [                "div",                "button",                "header",                "section",                "field",                "form"            ]        },        "label": {            "type": "string",            "description": "The label of the UI component, used for buttons or form fields"        },        "children": {            "type": "array",            "description": "Nested UI components",            "items": {                "$ref": "#"            }        },        "attributes": {            "type": "array",            "description": "Arbitrary attributes for the UI component, suitable for any element",            "items": {                "type": "object",                "properties": {                    "name": {                        "type": "string",                        "description": "The name of the attribute, for example onClick or className"                    },                    "value": {                        "type": "string",                        "description": "The value of the attribute"                    }                },                "required": [                    "name",                    "value"                ],                "additionalProperties": false            }        }    },    "required": [        "type",        "label",        "children",        "attributes"    ],    "additionalProperties": false}""".strip()
def generate_schema(description: str):    completion = client.chat.completions.create(        model="gpt-4o-mini",        response_format={"type": "json_schema", "json_schema": META_SCHEMA},        messages=[            {                "role": "system",                "content": META_PROMPT,            },            {                "role": "user",                "content": "Description:\n" + description,            },        ],    )
    return json.loads(completion.choices[0].message.content)

虽然OpenAI目前使用元提示和模式,但将来可能会集成更先进的技术,如DSPy

https://platform.openai.com/docs/guides/prompt-generation?context=structured-output-schema斯坦福,OpenAI Meta-Prompting: https://arxiv.org/pdf/2401.12954​​​​​​​

福利利领取:

IT类包含:
Java、云原生、GO语音、嵌入式、Linux、物联网、AI人工智能、python、C/C++/C#、软件测试、网络安全、Web前端、网页、大数据、Android大模型多线程、JVM、Spring、MySQL、Redis、Dubbo、中间件…等最全厂牌最新视频教程+源码+软件包+面试必考题和答案详解。

资源目录索引icon-default.png?t=O83Ahttps://path.dirts.cn/sfoA5TURw

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/448371.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

仓库管理系统有哪些功能?

上一篇,我们向大家介绍了一下仓库管理是什么,仓库管理操作流程有哪些,仓库管理系统又有哪些基本功能,那么接下来这篇文章,我们会详细介绍一下仓库管理系统各个功能是如何运作,是怎样解决企业中碰到的难题的…

mysql查看和修改默认配置

1.查看最大连接数 SELECT max_connections; 或者 SHOW VARIABLES LIKE max_connections;2.查看当前连接的客户端 SHOW PROCESSLIST;2.临时设置最大连接数 SET GLOBAL max_connections 500;3.临时设置连接客户端交互超时时间 SET GLOBAL interactive_timeout 1800;4.永久生…

HJ2 计算某字符出现次数

代码&#xff08;首刷自解 2024年10月16日&#xff09; #include <iostream> using namespace std;int main() {string input;getline(cin, input);char target;cin >> target;char t2;if (target > a && target < z) {t2 target (A - a);} else …

华为---Super VLAN简介及示例配置

目录 1. Super VLAN技术产生背景 2. Super VLAN概念 3. Super VLAN应用场景 4. Super VLAN工作原理 5. Super-VLAN主要配置命令 6. Super-VLAN主要配置步骤 7. 示例配置 7.1 示例场景 7.2 网络拓扑 7.3 配置代码 7.4 代码解析 7.5 测试验证 1. Super VLAN技术产生背…

低空产业园搭建技术详解

低空产业园的搭建技术是一个复杂而系统的工程&#xff0c;涉及多个方面的技术和策略。以下是对低空产业园搭建技术的详细解析&#xff1a; 一、规划与设计 1. 总体规划&#xff1a;低空产业园的规划需要结合地方经济发展、产业基础、政策导向等因素&#xff0c;制定科学合理的…

Meta Llama 3强势来袭:迄今最强开源大模型,性能媲美GPT-4

前言 Meta的最新语言模型Llama 3已经发布&#xff0c;标志着在大型语言模型&#xff08;LLM&#xff09;领域的一次重大突破&#xff0c;其性能在行业内与GPT-4相媲美。此次更新不仅提升了模型的处理能力和精确性&#xff0c;还将开源模型的性能推向了一个新的高度。 Hugging…

java在线招投标|评标|竞标|单一采购|邀标|评审专家|采购软件源码

​功能描述 1、门户管理&#xff1a;所有用户可在门户页面查看所有的公告信息及相关的通知信息。主要板块包含&#xff1a;招标公告、非招标公告、系统通知、政策法规。 2、立项管理&#xff1a;企业用户可对需要采购的项目进行立项申请&#xff0c;并提交审批&#xff0c;查看…

【C++11】包装器:深入解析与实现技巧

C 包装器&#xff1a;深入解析与实现技巧 个人主页 C专栏 目录 引言包装器的定义与用途C 包装器的常见应用场景实现包装器的技巧使用 RAII 实现资源管理案例分析&#xff1a;智能指针模板包装器的应用包装器与设计模式性能优化更多应用案例总结 引言 C 是一门灵活且强大的语…

Internet Download Manager6.42(简称IDM)2024免费网络资源下载神器

Internet Download Manager (IDM)是一个专业的网络下载器&#xff0c;拥有强大的下载管理能力。使用多线程下载&#xff0c;将文件分割为多个部分分别进行下载&#xff0c;完成后进行组合&#xff0c;达到快速下载文件的目的。可与浏览器集成&#xff0c;接替浏览器的所有下载任…

NewStarCTF2024-Week2-Web-WP

目录 1、复读机 2、你能在一秒内打出八句英文吗 3、遗失的拉链 4、谢谢皮蛋 plus 5、PangBai 过家家&#xff08;2&#xff09; 1、复读机 测了下存在 ssti 没什么说的 fenjing 秒了 2、你能在一秒内打出八句英文吗 每次出来的需要提交的内容都不一样 exp&#xff1a; …

3.3 Thymeleaf语法

文章目录 引言Thymeleaf标签显示标签链接地址标签条件判断标签元素遍历标签 Thymeleaf表达式变量表达式选择变量表达式消息表达式链接表达式 Thymeleaf内置对象上下文对象上下文变量上下文区域请求对象响应对象会话对象日期对象 实战演练创建控制器创建模板页面 结语 引言 Thy…

sim卡文件系统

### 5.2 初始通信建立程序 初始通信建立程序应遵循3GPP TS 31.101 [55]的规定&#xff0c;但有以下限制&#xff1a; - 对于3V及以下的SIM卡&#xff0c;最大时钟频率为4MHz&#xff0c;因此必须遵守3GPP TS 31.101 [55]中规定的相应功耗限制。 - ATR内容&#xff1a;如果SIM在…

C++调试方法(Vscode)(二) ——本地调试(ROS版)

初学者在调试一段代码的时候&#xff0c;经常出于不明原因&#xff0c;写出bug&#xff0c;导致程序崩溃。但是定位崩溃的地方时&#xff0c;往往采用简单而朴素的方法&#xff1a;即采用cout或者printf进行输出。这种方式既原始&#xff0c;又低效。一个合格的工程师应该是通过…

NeRS: Neural Reflectance Surfaces for Sparse-view 3D Reconstruction in the Wild

阅读记录&#xff1a; 1. 2.优点1&#xff1a;我们的方法仅依赖于近似的相机位姿估计和粗略的类别级形状模板。 3.我们的关键见解是&#xff0c;我们可以强制执行基于表面的 3D 表示&#xff0c;而不是允许广泛用于体积表示的无约束密度。重要的是&#xff0c;这允许依赖于视…

C# 图像镜像

测试页面&#xff1a; 图像镜像是图像旋转变换的一种特殊情况&#xff0c;通常包括垂直方向和水平方向的镜像。水平镜像通常是以原图像的垂直中轴为中心&#xff0c;将图像分为左右两部分进行堆成变换。如下&#xff1a; 垂直镜像通常是以原图像的水平中轴线为中心&#xff0c;…

【NLP自然语言处理】03 - 使用Anaconda创建新的环境/pycharm切换环境

NLP基础阶段&#xff1a;创建新的虚拟环境 第一步&#xff1a;查看有多少个虚拟环境 conda env list 第二步&#xff1a;创建一个新的虚拟环境&#xff0c;起个名字&#xff1a;nlpbase 打开anconda prompt终端&#xff0c;输入命令: conda create -n nlpbase python3.10 第三步…

React Agent 自定义实现

目录 背景 langchin 中的 agent langchin 中 agent 的问题 langchain 的 agent 案例 自定义 React Agent 大模型 工具定义 问题设定 问题改写&#xff0c;挖掘潜在意图 React Prompt 下一步规划 问题总结 代码 背景 之前使用过 langchian 中的 agent 去实现过一些…

高级算法设计与分析 学习笔记12 贪心算法

首先我们来解决一个经典的活动选择问题&#xff1a; s代表开始时间&#xff0c;f代表结束时间 可以看到这是一个动态规划的算法 现在&#xff0c;我们要把这个解决办法转换成一个贪心算法 直觉上讲&#xff0c;每次都选最先结束的可以留下最多的资源 当然开始之前先要把所有时…

[Python学习日记-43] Python 中的迭代器

[Python学习日记-43] Python 中的迭代器 简介 可迭代对象 迭代器 总结 简介 前面我们学习了各种各样的数据类型&#xff0c;在使用它们的时候我们也时不时会听到可迭代对象这一个名词&#xff0c;而本篇我们将讲述的迭代器感觉和我们之前学的可迭代对象挺相关的&#xff0c…

URDF统一机器人建模语言

统一机器人建模语言 URDF&#xff08;Unified Robot Description Format&#xff09;统一机器人描述格式&#xff0c;URDF使用XML格式描述机器人文件。 我们从下面四个方面介绍URDF&#xff1a; URDF的组成介绍 URDF-Link介绍 URDF-Joint介绍 创建一个简单的URDF…