<p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">OpenAI公布了其最新的o1 模型官方提示词建议,OpenAI明确表示模型在简单的提示下表现最佳。一些提示工程技术,如少量示例提示或指示模型“逐步思考”,可能不会提高性能,有时甚至会妨碍它。以下是一些最佳实践:</p> <h3 data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">提示设计建议</h3> <p data-immersive-translate-paragraph="1" data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">在使用AI模型时,遵循以下最佳实践可以提升性能。关键点如下:</p> <ol data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">保持提示简单明了</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">模型擅长理解和响应简短、清晰的指令,而无需大量指导,避免使用过于复杂或详细的提示。</li> </ul> </li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">避免使用“逐步思考/链式思维”的提示</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">没有必要让模型“逐步思考”或解释其推理过程,因为模型已经内置了该能力,模型在已经内部处理推理。</li> </ul> </li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">使用分隔符提高清晰度</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">可以使用三重引号、XML标签或章节标题等分隔符来标记输入的不同部分,帮助模型更好地理解各个部分。</li> </ul> </li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">在检索增强生成(RAG)中限制额外的上下文</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">在提供额外上下文或文档时,仅包含最相关的信息,避免模型因过多信息而产生复杂或冗长的回复。</li> </ul> </li> </ol> <h3>提示示例</h3> <ul> <li>OpenAI o1 系列模型能够实现复杂的算法并生成代码。该提示要求 o1 根据一些特定标准重构一个 React 组</li> </ul> <blockquote>from openai import OpenAI client = OpenAI() prompt = """ Instructions: - Given the React component below, change it so that nonfiction books have red text. - Return only the code in your reply - Do not include any additional formatting, such as markdown code blocks - For formatting, use four space tabs, and do not allow any lines of code to exceed 80 columns const books = [ { title: 'Dune', category: 'fiction', id: 1 }, { title: 'Frankenstein', category: 'fiction', id: 2 }, { title: 'Moneyball', category: 'nonfiction', id: 3 }, ]; export default function BookList() { const listItems = books.map(book => <li> {book.title} </li> ); return ( <ul>{listItems}</ul> ); } """ response = client.chat.completions.create( model="o1-mini", messages=[ { "role": "user", "content": [ { "type": "text", "text": prompt }, ], } ] ) print(response.choices[0].message.content)</blockquote> <ul> <li data-pm-slice="0 0 []">OpenAI o1 系列模型也擅长创建多步骤计划。这个示例提示要求 o1 创建一个完整解决方案的文件系统结构,以及实现所需用例的 Python 代码。</li> </ul> <blockquote>from openai import OpenAI client = OpenAI() prompt = """ I want to build a Python app that takes user questions and looks them up in a database where they are mapped to answers. If there ia close match, it retrieves the matched answer. If there isn't, it asks the user to provide an answer and stores the question/answer pair in the database. Make a plan for the directory structure you'll need, then return each file in full. Only supply your reasoning at the beginning and end, not throughout the code. """ response = client.chat.completions.create( model="o1-preview", messages=[ { "role": "user", "content": [ { "type": "text", "text": prompt }, ], } ] ) print(response.choices[0].message.content)</blockquote> <ul> <li data-pm-slice="1 1 []">OpenAI o1 系列模型在 STEM 研究中表现出色。请求支持基础研究任务的提示应显示出强劲的结果。</li> </ul> <blockquote>from openai import OpenAI client = OpenAI() prompt = """ What are three compounds we should consider investigating to advance research into new antibiotics? Why should we consider them? """ response = client.chat.completions.create( model="o1-preview", messages=[ { "role": "user", "content": prompt } ] ) print(response.choices[0].message.content)</blockquote> <h3>具体案例</h3> <strong>如何将知识库文章转换为可以由语言模型(LLM)理解和执行的流程,特别是OpenAI的o1模型。</strong> <ul> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">流程结构</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">这些流程旨在将复杂的过程分解为明确且易于管理的步骤。</li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">每个步骤对应一个具体的操作,减少了歧义并防止模型产生错误的推断。</li> </ul> </li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">挑战</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">内部知识库文章通常包含复杂结构,如多步骤流程或决策树,LLM难以处理这些内容,除非有清晰的指令。</li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">模型必须处理各种边缘情况,并且提供一致的响应。</li> </ul> </li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">o1模型的能力</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">o1模型能够高效地解构文章,并将其转换为几乎不需要额外提示的流程(零样本推理),确保以最少的输入完成任务。</li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">它可以通过整合函数调用和清晰的操作序列,处理如客户服务任务等工作流程。</li> </ul> </li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">应用案例</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">文章描述了如何将OpenAI帮助中心的文章(如删除支付方式或设置预付费账单)转换为流程。这些流程引导LLM与用户互动并执行必要的操作(例如取消订阅)。</li> </ul> </li> </ul> 详细:<a href="https://cookbook.openai.com/examples/o1/using_reasoning_for_routine_generation" target="_blank" rel="noopener">https://cookbook.openai.com/examples/o1/using_reasoning_for_routine_generation</a> <strong>如何使用OpenAI的o1模型(特别是o1-preview版)来通过推理执行数据验证。</strong> 通过一个合成的医疗数据集展示了如何识别数据中的问题,并分析模型的准确性。 <ul> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">数据验证的重要性</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">数据验证对于确保数据集的质量和可靠性至关重要,特别是在医疗等敏感领域。传统的验证方法依赖预定义规则,而o1模型可以通过上下文理解和推理提供更加灵活、智能的验证方式。</li> </ul> </li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">示例数据集生成</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">文中生成了一个包含错误的合成医疗数据集,包括患者ID、出生日期、性别、病史、当前药物、过敏、实验室结果、诊断和治疗方案等字段。</li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">错误的类型包括药物与过敏症矛盾、诊断与治疗不匹配等。</li> </ul> </li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">验证过程</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">模型通过推理分析数据的每一行,判断数据是否有效,并解释问题所在。之后将结果与“正确答案”进行比对,计算模型识别问题的准确性。</li> </ul> </li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">性能评估</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">通过精确度、召回率和F1得分来衡量模型的表现。在测试中,模型对问题的识别精度达到0.82,召回率为0.87,F1得分为0.84。</li> </ul> </li> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <p data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"><strong data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">未来应用</strong>:</p> <ul data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b"> <li data-immersive-translate-walked="f9d03d4b-49de-43b7-8380-aff00f3f810b">这种基于推理的数据验证方法可以广泛应用于多个领域的评估集,从而简化数据验证流程,提高自动化的可靠性。</li> </ul> </li> </ul> 详细介绍:<a href="https://cookbook.openai.com/examples/o1/using_reasoning_for_data_validation" target="_blank" rel="noopener">https://cookbook.openai.com/examples/o1/using_reasoning_for_data_validation</a>