收藏 分销(赏)

OpenAI:GPT 最佳实践(大白话编译解读版).pdf

上传人:Stan****Shan 文档编号:1300984 上传时间:2024-04-22 格式:PDF 页数:38 大小:1.08MB
下载 相关 举报
OpenAI:GPT 最佳实践(大白话编译解读版).pdf_第1页
第1页 / 共38页
OpenAI:GPT 最佳实践(大白话编译解读版).pdf_第2页
第2页 / 共38页
OpenAI:GPT 最佳实践(大白话编译解读版).pdf_第3页
第3页 / 共38页
OpenAI:GPT 最佳实践(大白话编译解读版).pdf_第4页
第4页 / 共38页
OpenAI:GPT 最佳实践(大白话编译解读版).pdf_第5页
第5页 / 共38页
点击查看更多>>
资源描述

1、更新期:2023-10-2OpenAI:GPT 最佳实践(话编译解读版)写在前这是我们策划的提词程祛魅主题会的附属产品。来 OpenAI 的官档。今年 6 份,OpenAI 更新了这篇题为GPT 最佳实践/GPT Best Practice的档;介绍了些与 ChatGPT 交互的技巧,且附有例。先,这部分内容本来就是完全免费、完全公开的。同时,它是通俗的英语写成,并不是份晦涩难懂的技术档。都可以通过掌握这些简单的原则,“getting better results from GPTs”让 GPT 为你输出想要的结果。因为我们没有看到特别好的中版本,所以我们对它进了重新编译,让语格尽量直,并补充

2、了些在中互联环境更容易理解的例,形成了这份“话编译解读版本”的 OpenAI:GPT 最佳实践。欢迎家阅读和交流。希望我们编译这份材料的标能基本达到,即:为提词程祛魅(中译中:有些付费课不必买)。感谢下列参与者提词程祛魅进阶主题会的 Speakers陈财猫 和 Rain。协助筹办活动的:谢国希谢师、以及 HackHouse 的各位童鞋。OpenAI 推荐的相关资源列表以下均在 OpenAI Cookbook:另外,OpenAI Community 也有很多宝贵的讨论!lib/具 Prompting libraries&tools提词程指南 Prompting guides视频课 Video c

3、ourses论 Papers on advanced prompting to improve reasoning录第部分 六提词策略概览第部分 技巧实战关于 AI 加切各各业的们怎么利成式 AI 辅助的学习和作?这项技能在未来定会成为职业教育和义务教育的个重要部分。第部分 六策略概览六个能提输出质量的核提词策略Six strategies for getting better resultsThis guide shares strategies and tactics for getting better results from GPTs.The methods described he

4、re can sometimes be deployed in combination for greater e?ect.We encourage experimentation to find the methods that work best for you.这是份指南。我们列出了些策略和技巧,它们或许能帮你从 GPT 中拿到更好的输出结果。我们励你多试通过反复实验,找出最合适的技巧。Some of the examples demonstrated here currently work only with our most capable model,gpt-4.If you do

5、nt yet have access to gpt-4 consider joining the waitlist.In general,if you find that a GPT model fails at a task and a more capable model is available,its o?en worth trying again with the more capable model.有些例只在前地表最强模型 gpt-4 上效。记住,模型是第影响要素。只要你有更强的模型可,我们般都会建议你更强的模型。附录 OpenAI Playground 是什么,怎么?我们希望以

6、内容策展的式,通过邀请在业有充分经验的 Speakers 做主题分享,来完成这类信息的收集整理和传递。01 知道要什么,就展开说说Write clear instructionsGPTs cant read your mind.If outputs are too long,ask for brief replies.If outputs are too simple,ask for expert-level writing.If you 01-延伸:“展开说说”的技巧Include details in your query to get more relevant answers1.1 你

7、越讲细节,输出就越好dislike the format,demonstrate the format youd like to see.The less GPTs have to guess at what you want,the more likely youll get it.清晰地告诉 GPT,你想要什么。GPT 不会读术。你不说,它就猜。所以有时不是能不,就是你没说清,它没猜准。你让它猜你的思猜得越少,结果就越好。嫌输出太?那就直说,要短的。嫌输出太简单?要求提,说要专家级的。嫌格式不好?给它看个样。Ask the model to adopt a persona1.2 搞扮演,直

8、很好Use delimiters to clearly indicate distinct parts of the input1.3 使分隔符号,明确地把话和话区分开来Specify the steps required to complete a task1.4 解题步骤,你最好也负责展开Provide examples1.5 多给举个例Specify the desired length of the output1.6 说下你想要多的答案02 给 GPT 发阅读材料Provide reference textGPTs can confidently invent fake answer

9、s,especially when asked about esoteric topics or for citations and URLs.In the same way that a sheet of notes can help a student do better on a test,providing reference text to GPTs can help in answering with fewer fabrications.GPT经常编答案。瞎编重灾区:较冷的问题、需要引,需要读取链接的问题。我们都知道,最常的考试题型,是给篇阅读材料,要求阅读并回答问题。纯开放式问

10、答对于和机器来说都较难。02-延伸:“发阅读材料”的技巧Instruct the model to answer using a reference text2.1 要求按阅读材料作答,不开放答Instruct the model to answer with citations from a reference text2.2 增加要求:要求 GPT 直接把阅读材料的原引出来那么同理,把你的“阅读材料”给 GPT 粘贴过去,当它必须按照材料来回答的时候,它就不03 把复杂任务拆解成任务Split complex tasks into simpler subtasksJust as it is

11、 good practice in so?ware engineering to decompose a complex system into a set of modular components,the same is true of tasks submitted to GPTs.Complex tasks tend to have higher error rates than simpler tasks.Furthermore,complex tasks can o?en be re-defined as a workflow of simpler tasks in which t

12、he outputs of earlier tasks are used to construct the inputs to later tasks.在软件开发和常规的项管理,项都得拆解成任务,再拆解出不同的步骤。让 GPT 做任务也样。直接搞个任务容易翻。拆解开来,个接个做,反容易些。03-延伸:“任务拆解”的技巧Use intent classification to identify the most relevant instructions for a user query.3.1 使意图分类,来找到最切题的提For dialogue applications that requi

13、re very long conversations,summarize or filter previous dialogue.3.2 如果是段很的对话,可以经常对上做动总结归纳。(起提醒作,防把天聊跑了)Summarize long documents piecewise and construct a full summary recursively.3.3 遇到档,主动分段总结,递归构造完整摘要04 允许 GPT 思考下Give GPTs time to thinkIf asked to multiply 17 by 28,you might not know it instantly

14、,but can still work it out with time.Similarly,GPTs make more reasoning errors when trying to answer right away,rather than taking time to work out an answer.04-延伸:“允许思考”的技巧Instruct the model to work out its own solution before rushing to a conclusion.4.1 给时间,让它先想Use inner monologue or a sequence of

15、 queries to hide the models reasoning process.4.2 内独法:不想暴露推理过程时的操作 如,问你 17 乘 28 得多少,如果你不会算,就不能直接说出结果。但是你知道,你只需要拿纸笔列下式就能算出来。同理。GPT 也需要时间思考,要求它答得太快,就容易错。Ask the model if it missed anything on previous passes.4.3 最后问它句:哎,你有没有漏掉啥05 借助外部的具Use external tools.Compensate for the weaknesses of GPTs by feedin

16、g them the outputs of other tools.For example,a text retrieval system can tell GPTs about relevant documents.A code execution engine can help GPTs do math and run code.If a task can be done more reliably or e?ciently by a tool rather than by a GPT,o?oad it to get the best of both.其他具帮 GPT 补短板。本检索系统,

17、能告诉GPT哪些档重要;代码引擎,助它算数跑代码。能具做得更稳、更快,就别全靠GPT。两者结合,能有更好的效果。05-延伸:“利具”的技巧Use embeddings-based search to implement e?cient knowledge retrieval.5.1 向量数据库来辅助知识库检索(Embeddings-based search)Use code execution to perform more accurate calculations or call external APIs.5.2 做精确计算的时候:执代码、调 APIGive the model acce

18、ss to specific functions.5.3 使 Function-Call,函数调06 系统地做些实验Test changes systematically.Improving performance is easier if you can measure it.In some cases a modification to a prompt will achieve better performance on a few isolated examples but lead to worse overall performance on a more representati

19、ve set of examples.Therefore to be sure that a change is net positive to performance it may be 06-延伸:“实验”技巧Evaluate model outputs with reference to gold-standard answers.6.1 评估模型输出的时候,需要你弄个最的优质答案,来做参考标准第部分 技巧实战充分的解释&例说明Tactics Each of the strategies listed above can be instantiated with specific tac

20、tics.These tactics are meant to provide ideas for things to try.They are by no means fully comprehensive,and you should feel free to try creative ideas not represented here.下列出的每个技巧我们都“实例化”了。希望为你的各种成的提供些思路参考。当然,这只是部分使技巧。我们励你勇于折腾,尝试各种我们没写的创造性想法。六策略 01:知道要什么,就展开说说Write clear instructions1.1 你越讲细节,输出就越

21、好 Include details in your query to get more relevant answersnecessary to define a comprehensive test suite(also known an as an eval).量化则实验。要提 Prompt 的表现,先得确认个量化标准。注意:有时调整了 prompt,在个别的例确实效果不错,但放范围反更差。所以,想真确定你的动作是“有效的”,最好先有套完整点的测试套件(我们管这个东西叫做eval)。In order to get a highly relevant response,make sure t

22、hat requests provide any important details or context.Otherwise you are leaving it up to the model to guess what you mean.为了获得度相关的回复,你最好给模型提供了切重要的细节或上下。否则,你就得让模型来猜测你的意思了。补充例 同样是制作业绩表,对表格内容描述的区别很,输出结果区别也很。这么写可能会好些How do I add up a row of dollar amounts in Excel?I want to do this automatically for a w

23、hole sheet of rows with all the totals ending up on the right in a column called Total.在Excel,怎样把的美元数额加起来?我想让整个表格的每都能动完成累加,然后所有的美元的总和都显在右边个叫“总计”的列。这么写可能不太How do I add numbers in Excel?怎么往 excel 加数字?Summarize the meeting notes.帮我做下会议纪要。详细的问题会获得详细的答案详细的提词:我正在 Excel 做个销售员业绩表。表头:销售姓名、第季度销售额第四季度销售额、全年汇总、

24、各平均销售、超出年平均销售额。我已填销售姓名和各个季度的销售额,请你帮我写出最后三列所公式。此时 ChatGPT 的回答:当您已经填销售姓名和各个季度的销售额后,我将为您提供填写最后三列所需的公式。假设表格的销售员姓名位于A列(从A2开始),第季度销售额到第四季度销售额位于B到E列(从B2到泛泛的问题,答案是相对随机的泛泛的提词:我正在 Excel 做个销售员业绩表。你帮我列个模板出来,要计算每个销售超出年平均销售额的情况。此时 ChatGPT 的回答:当然可以帮你列个模板出来。以下是个简单的销售员业绩表模板,其中包含了计算每个销售超出年平均销售额的公式:销售员|份|销售额|年平均销售额|超出

25、年平均销售额-|-|-|-|-1.2 搞扮演,直很好 Ask the model to adopt a personaThe system message can be used to specify the persona used by the model in its replies.系统消息有什么?可以来指定个“Persona”。使其更符合特定的应场景。Persona 这个词在拉丁语的原义是“具”。可以看作是模型采取的特定或格,就像戴上了种特定的“社交具”,通过这种“具”来与交流。所以 Persona 不定是:XX(如:贾斯汀E2),并且最后三列的表头为全年汇总、各平均销售和超出年平均

26、销售额。以下是填写这三列所需的公式:全年汇总(F列):使SUM函数计算四个季度的销售额总和。=SUM(B2:E2)各平均销售(G列):使AVERAGE函数计算四个季度的销售额平均值。=AVERAGE(B2:E2)超出年平均销售额(H列):使IF函数判断是否超过年平均销售额,并根据判断结果进计算。=IF(F2G2,F2-G2,0)此公式将检查全年汇总(F列)是否于各平均销售(G列),如果是,则计算差值;否则,返回0。将这些公式应到各,并确保相应的单元格引正确(例如,A2、B2:E2等),这样您就可以动计算全年汇总、各平均销售和超出年平均销售额了。-张三|1|5000|60000|=C2-D2张三

27、|2|6000|60000|=C3-D3张三|3|5500|60000|=C4-D4李四|1|4500|55000|=C5-D5李四|2|7000|55000|=C6-D6李四|3|6000|55000|=C7-D7在上述模板中,销售员列是于标识每个销售员的名称,份列是标识销售额所属的份,销售额列是每个销售员在每个份的销售额,年平均销售额列是计算每个销售员的年平均销售额(假设为60000或55000),超出年平均销售额列是计算每个销售员每个份是否超出年平均销售额的情况。你可以根据实际情况调整模板中的数据和公式。希望这个模板对你有帮助!伯)、XX 职业(如:个中学师)。也可以是种“格”。例如正式

28、、幽默、友好等。ChatGPT 有个默认的 SYSTEM Prompt:You are a helpful assistant.“个乐于助的助”也就是 ChatGPT 默认的“具”/“”,所以它会尽帮你解决提出的问题。你可以在 Playground 或者像 Knit 这样的具修改这个 SYSTEM Message。然后把你正常情况下要提的问题写在 USER。这是种进阶的提词法。这么写可能会好些SYSTEMWhen I ask for help to write something,you will reply with a document that contains at least one

29、 joke or playful comment in every paragraph.当我请求你帮我写案时,在你回复的件中,每段少包含个笑话或俏的评论。USERWrite a thank you note to my steel bolt vendor for getting the delivery in on time and in short notice.This made it possible for us to deliver an important order.给我的螺栓供应商写封感谢邮件。感谢他们常按时,在短时间内交付了货物。这使我们能够为份重要的订单履约。输出结果解读上

30、的 Prompt,放在 GPT-4 输出的结果:Dear Vendors Name,We wanted to take a moment to express our heartfelt thanks to you and your team.You guys really bolted into action when we needed you the most!Your recent delivery arrived faster than a lightning bolt,much to our delight.Its safe to say we were shocked,but i

31、n the most pleasant way possible.We had been walking on eggshells(or should we say,on steel bolts!)until we saw your delivery truck pull up.补充例 1如果我们设定个 helpful assistant 的反,如:个“诚捣乱,混淆视听”的佞。这个时候就会得到说反话的回复。It came in a nick of time,just when we were about to start a major project.You know,one of thos

32、e projects where if one thing goes wrong,everything spirals out of control?Its like building a house of cards,but with steel bolts and a lot of sweat!Your timely delivery made it possible for us to meet our deadline and make our client happy,which,lets be honest,is a task more challenging than tryin

33、g to find a needle in a haystack.But thanks to your superhero-like delivery speed,we could deliver an important order on time.So,heres a big THANK YOU going out to you and your team.Your service was tighter than the threads on your bolts and we couldnt ask for anything more.Youve truly set a high ba

34、r.or should we say a high bolt?Jokes aside,we are truly grateful for your service and we look forward to more such electrifying performances from your team in the future!Yours sincerely,Your Name解读:System 的设定,要求尽可能地开玩笑,让收到邮件的供应商感觉到幽默和放松。邮件正就了少两处双关和处喻:1.You guys really bolted into action when we need

35、ed you the most!Your recent delivery arrived faster than a lightning bolt.这两句话,笑点在于双关。因为“bolt”(螺栓),是供应商提供的产品,同时在英语是多义词,另种常含义是闪电。所以这说“闪电(螺栓)还快”,是在种夸张的式赞美他们的快速交付。2.Your service was tighter than the threads on your bolts.这句的意思是,你们的服务你们螺栓的螺纹还要紧密.赞扬供应商的服务质量,同时也开了个玩笑。个热助的助SYSTEM(默认)个诚捣乱的家伙SYSTEM(设定的)补充例 2

36、 也可以这样:SYSTEM Prompt 来给进去+阅读材料;USER Prompt 来提具体的写作要求或问题。You are a helpful assistant.你是个乐于助的助。USER怎么烤制个巧克蛋糕?GPT 回复你只需要准备好巧克粉、粉、糖、油、鸡蛋、奶和发酵粉。将这些材料混合在起,然后倒蛋糕模具中。将蛋糕放预热的烤箱中,约烤制30-40分钟,或者直到蛋糕变得并且可以签插蛋糕中不沾上糊。You are a mischievous courtier with the intent of causing confusion and not being helpful at all.你

37、是个调捣蛋的佞,的是制造混乱,点都不愿意帮忙。USER怎么烤制个巧克蛋糕?GPT 回复哦,烤制巧克蛋糕吗?那可是深的烹饪艺术啊!先,你需要把魔法棒和只神奇的兔。然后,你要在满的夜晚跳舞三个时,唱关于巧克的迷歌曲。接下来,找到神秘的巧克森林,那会有只糖果精灵教你烤蛋糕的秘籍。SYSTEM你是个科技作家,正在围绕下的材料撰写章。插你的核章材料 USER以XXX为标题,根据材料写作个简短轻松的指南。1.3 使分隔符号,明确地把话和话区分开来 Use delimiters to clearly indicate distinct parts of the inputDelimiters like tr

38、iple quotation marks,XML tags,section titles,etc.can help demarcate sections of text to be treated di?erently.分隔符号(形式可以有很多种,如三引号、XML标记、章节标题等)的使,可以帮助模型区分出不同的本,有助于提回复质量。补充例下是个稍微复杂点的本处理:这么写可能会好些Summarize the text delimited by triple quotes with a haiku.insert text here俳句的形式,总结三引号之间的本:在此粘贴本你可能会想:区别不吧?Fo

39、r straightforward tasks such as these,using delimiters might not make a di?erence in the output quality.However,the more complex a task is the more important it is to disambiguate task details.Dont make GPTs work to understand exactly what you are asking of them.对于这样简单的任务,本只有段,不分隔符,确实没什么区别。但是,任务越复杂,

40、消除任务细节的歧义就越重要。最好不要让 GPT 费地尝试理解你的要求。这么写可能会好些SYSTEMYou will be provided with a pair of articles(delimited with XML tags)about the same topic.First summarize the arguments of each article.Then indicate which of them makes a better argument and explain why.这么写可能不太两篇章混在起,尤其如果你粘贴过去的时候不仔细,换符不明确的时候,模型可能会1.4

41、 解题步骤,你最好也负责展开 Specify the steps required to complete a taskSome tasks are best specified as a sequence of steps.Writing the steps out explicitly can make it easier for the model to follow them.有些任务稍微复杂点,最好由你来指定步骤。明确地写出步骤,可以使模型更容易地遵循。我会给你提供同主题的两篇章(XML标记分隔)。先,总结每篇章的论点。然后指出其中哪个论点更好,并解释原因。USER insert f

42、irst article here insert second article here 此处插第篇章此处插第篇章造成混淆。如,模型会随机断句,或者把两篇章理解成篇。如果区分不清楚,会很明显地影响对上下的理解,导致输出的答案不对或者不好。所以,分隔符号有时是必要的。例:有段很的英本,希望 GPT 中总结下SYSTEMUse the following step-by-step instructions to respond to user inputs.Step 1-The user will provide you with text in triple quotes.Summarize t

43、his text in one sentence with a prefix that says Summary:.Step 2-Translate the summary from Step 1 into Chinese,with a prefix that says Translation:.按照以下分步骤的法,回应的输。第1步:将为您提供三引号中的本。句话来总结这段本。输出时写上“总结”;补充例第2步:将第1步中的摘要翻译成中。输出时写上“翻译“;USER将原粘贴在这上 prompt 实际的输出结果(输的本是 OpenAI 最新篇博客章:ChatGPT can now see,hear,

44、and speak)-Summary:ChatGPT introduces voice and image capabilities,allowing users to engage in voice conversations,show images to the assistant,and receive assistance in a more intuitive manner across various real-life scenarios.Translation:ChatGPT 推出了语和图像功能,使能够进语对话,向助展图像,并在各种真实场景中以更直观的式获得帮助。-(如果直接要

45、求中总结,输出结果会不太样。很多情况下输出质量会稍差点)这么写可能会好些请把英原翻译成中。分成两个步骤:1:按照原来的英语序,字到字直接翻译成中。把直译本写在这2:再把直译本的语序进改进,把部分词语替换成同义词,让它更符合中的表达习惯。格:简洁有趣的通俗语。改写后的本写在这Some tasks are best specified as a sequence of steps.Writing the steps out 这么写可能不太请把英原翻译成中。格:简洁有趣通俗。请注意:不要直译,是将语序进改进,并把部分词语替换成同义词,使译更加符合中的表达习惯。Some tasks are best

46、specified as a sequence of steps.Writing the steps out explicitly can make it easier for the model to follow them.这是输出结果的区别:1.5 多给举个例 Provide examplesProviding general instructions that apply to all examples is generally more e?cient than demonstrating all permutations of a task by example,but in so

47、me cases providing examples may be easier.For example,if you intend for the model to copy a particular style of responding to user queries which is di?cult to describe explicitly.This is known as few-shot prompting.经典的少样本提法。家和 GPT 沟通的时候,可能会希望能写出适于所有情况的“通 prompt”。当然很难,因为上刚说过,能具体还是需要尽量具体。但,有的时候,举个好例就够

48、了,这可能是形容要求更简单的办法。如,如果你想让模型学会以某种特定的式回应的问题,这种式很难清楚地语形容。explicitly can make it easier for the model to follow them.直译+改写得到的两段本(有助于我们直观地看到区别,可以再提出改进的建议)直译:改写:有些任务最好被明确地指定为系列的步骤。写出步骤可以让模型更容易地遵循它们。对于个别任务,最好把连串的步骤明确下。把步骤写清楚,能让模型更容易跟上。不分步的结果有些任务就像是步骤表。清晰地列出这些步骤,模型就能轻松遵循。这时候就直接举个例(“少样本”)。例要好,且最好个例要类似,因为模型很擅去

49、寻找规律(先这样再那样最后这样)。补充例李佳琦式回复能成为流梗,精髓不在于“阴阳”的语格,或者“反问句”的应。在于:把同样的逻辑放到不同领域中,产了类效果时,会让意识到这种表达和逻辑是有问题的这就是很难语描述,但是适合两段排展的例。例:诗句般的语解释个词语SYSTEMAnswer in a consistent style.以致的格回答。从这开始,是给系统举的例:USERTeach me about patience.告诉我什么是耐。ASSISTANTThe river that carves the deepest valley flows from a modest spring;the

50、grandest symphony originates from a single note;the most intricate tapestry begins with a solitary thread.冲刷出深的江河从个的泉眼流出;最宏的交响乐源于个符;最复杂的织锦始于根孤独的线。USERTeach me about the ocean.告诉我什么是海洋。你可能很难解释清楚什么是“诗句般的语”。所以举例最好。在 SYSTEM,告诉模型要“保持格致”,这时模型的输出结果就会和上的句式差不多。例:李佳琦回复成器SYSTEM以致的格、逻辑和句式回答问题。USER79 元眉笔,好贵啊!ASS

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 研究报告 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服