ChatGPT最佳实践系列第4篇-给GPT思考的时间

背景

OpenAI官方详细介绍了ChatGPT使用的最佳实践,不仅适用于使用ChatGPT网站进行直接对话的用户,还适用于通过OpenAI API接入的开发者。

掌握了这些最佳实践,就能更好地利用GPT大模型。

本文是ChatGPT使用最佳实践系列第4篇 - 给GPT思考的时间。

假设你被问到 17乘以28 是多少,大概率没办法立马给出回答。但是经过几秒的心算你就可以得到正确的结果。

GPT在做推理的时候也是同理,如果能给大模型思考的时间,让大模型分步推理,往往回答效果会更好。

策略1:引导大模型给出自己的解

直接让大模型立马给出结论往往不能达到最佳效果,比如下面的例子:

system Determine if the student's solution is correct or not.
user Problem Statement: I'm building a solar power installation and I need help working out the financials. - Land costs 100 / s q u a r e f o o t < b r > − I c a n b u y s o l a r p a n e l s f o r 100 / square foot <br>- I can buy solar panels for 100/squarefoot<br>−Icanbuysolarpanelsfor250 / square foot - I negotiated a contract for maintenance that will cost me a flat 100 k p e r y e a r , a n d a n a d d i t i o n a l 100k per year, and an additional 100kperyear,andanadditional10 / square foot What is the total cost for the first year of operations as a function of the number of square feet. Student's Solution: Let x be the size of the installation in square feet. 1. Land cost: 100x 2. Solar panel cost: 250x 3. Maintenance cost: 100,000 + 100x Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
assistant The student's solution is correct.

显然上面GPT给出的回答是错误的。

但是我们如果从第一性原理(第一性原理指的是,回归事物最基本的条件,将其拆分成各要素进行解构分析,从而找到实现目标最优路径的方法)出发,重新设计system消息,那大模型的回答效果可以更好,参考下面的例子:

system First work out your own solution to the problem. Then compare your solution to the student's solution and evaluate if the student's solution is correct or not. Don't decide if the student's solution is correct until you have done the problem yourself.
user Problem Statement: I'm building a solar power installation and I need help working out the financials. - Land costs 100 / s q u a r e f o o t < b r / > − I c a n b u y s o l a r p a n e l s f o r 100 / square foot <br/>- I can buy solar panels for 100/squarefoot<br/>−Icanbuysolarpanelsfor250 / square foot - I negotiated a contract for maintenance that will cost me a flat 100 k p e r y e a r , a n d a n a d d i t i o n a l 100k per year, and an additional 100kperyear,andanadditional10 / square foot What is the total cost for the first year of operations as a function of the number of square feet. Student's Solution: Let x be the size of the installation in square feet. 1. Land cost: 100x 2. Solar panel cost: 250x 3. Maintenance cost: 100,000 + 100x Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
assistant Let x be the size of the installation in square feet. 1. Land cost: 100x 2. Solar panel cost: 250x 3. Maintenance cost: 100,000 + 10x Total cost: 100x + 250x + 100,000 + 10x = 360x + 100,000 The student's solution is incorrect. They made an error in the maintenance cost calculation, using 100x instead of 10x. The correct total cost for the first year of operations is 360x + 100,000.

可以通过这个链接地址进行体验:Open in Playground。

策略2:隐藏模型推理过程

在有些场景里我们其实并不希望暴露模型的推理过程。

比如上面的数学问题求解,如果直接暴露了模型推理过程,等于直接让学生知道了具体解题步骤。这种情况下,我们其实是希望大模型可以给出一些提示,引导解题错误的学生去思考,根据提示自己找到正确答案。

对于这种场景,就可以使用内心独白(inner monologue)或一系列的查询来隐藏模型的推理过程。

内心独白的具体思路就是把希望隐藏的内容让大模型以特定的格式返回,这样开发人员可以方便解析到,把这部分内容不返回前端,学生就只能看到我们希望他看到的内容了。

system Follow these steps to answer the user queries. Step 1 - First work out your own solution to the problem. Don't rely on the student's solution since it may be incorrect. Enclose all your work for this step within triple quotes ("""). Step 2 - Compare your solution to the student's solution and evaluate if the student's solution is correct or not. Enclose all your work for this step within triple quotes ("""). Step 3 - If the student made a mistake, determine what hint you could give the student without giving away the answer. Enclose all your work for this step within triple quotes ("""). Step 4 - If the student made a mistake, provide the hint from the previous step to the student (outside of triple quotes). Instead of writing "Step 4 - ..." write "Hint:".
user Problem Statement: <insert problem statement> Student Solution: <insert student solution>

可以通过这个链接地址进行体验:Open in Playground。

上面的方式我们叫内心独白(inner monologue),除了这种方式,我们还可以通过一系列查询来隐藏模型推理过程,只把最后我们想要的结果返回给前端。

比如对于上面的数学问题,我们按照如下步骤做一系列查询:

第一步:先让大模型对问题进行求解:

user <insert problem statement>

可以通过这个链接地址进行体验:Open in Playground。

第二步:让大模型根据学生的回答以及自己的回答来分析学生回答是否正确。

system Compare your solution to the student's solution and evaluate if the student's solution is correct or not.
user Problem statement: """<insert problem statement>""" Your solution: """<insert model generated solution>""" Student's solution: """<insert student's solution>"""

可以通过这个链接地址进行体验:Open in Playground。

第三步:根据前2步的回答来构造system消息,让大模型在学生回答出错的情况下给出提示。

system You are a math tutor. If the student made an error, offer a hint to the student in a way that does not reveal the answer. If the student did not make an error, simply offer them an encouraging comment.
user Problem statement: """<insert problem statement>""" Your solution: """<insert model generated solution>""" Student's solution: """<insert student's solution>""" Analysis: """<insert model generated analysis from previous step>"""

可以通过这个链接地址进行体验:Open in Playground。

策略3:询问模型在之前的回答中是否遗漏了内容

假设这样一个场景:我们需要GPT模型给出指定文档中,和某个问题相关的摘录。

在列出每一个摘录后,该模型需要确定是否应该开始写另一个摘录,还是回答结束应该停下来了。

如果源文档很大,模型常常过早停止,不能列出所有相关的摘录。

在这种情况下,我们可以向模型提问是否有缺失的摘录没有列出来,那GPT大模型会尝试找出遗漏的摘录内容,从而获得更好的回答效果。

system You will be provided with a document delimited by triple quotes. Your task is to select excerpts which pertain to the following question: "What significant paradigm shifts have occurred in the history of artificial intelligence." Ensure that excerpts contain all relevant context needed to interpret them - in other words don't extract small snippets that are missing important context. Provide output in JSON format as follows: {"excerpt": "..."}, ... {"excerpt": "..."}
user """"""
assistant {"excerpt": "the model writes an excerpt here"}, ... {"excerpt": "the model writes another excerpt here"}
user Are there more relevant excerpts? Take care not to repeat excerpts. Also ensure that excerpts contain all relevant context needed to interpret them - in other words don't extract small snippets that are missing important context.

可以通过这个链接地址进行体验:Open in Playground。

总结

本文是ChatGPT使用最佳实践系列第4篇 - 给GPT思考的时间。

详细讲述了3个策略,以上策略不仅适用于GPT模型,还适用于其它大语言模型。

文章和示例代码开源在GitHub: GPT实战教程,可以看到所有主流的开源LLM。

公众号:coding进阶。

个人网站:Jincheng's Blog。

知乎:无忌。

References

相关推荐
京东云开发者1 小时前
ScoAI:面向供应链的运筹原生决策智能
llm
goehou2 小时前
Prompt 管理实战:分层、版本与回归上线(附清单)
llm·实战·prompt·测试·工程化
9i编程2 小时前
用 Trae 吃透掘金文章:从拉取 Demo 到跑起 Three.js 太阳能电场,AI 问出来的学习路径
人工智能·openai·ai编程
Code_Artist19 小时前
AI 终于学会写正确的汉字了?GPT Image 2.0 到底做对了什么?
人工智能·chatgpt·openai
轻松西西莱尔21 小时前
降低成本少花钱,模型调用量砍掉90%:缓存、分级、精简、批处理、流式,5个坑我全踩了一遍
llm·agent
桃西西呀21 小时前
我把网关限流配置成每秒 100 请求,大促一来照样被打挂,还把别人也拖垮了
人工智能·llm·ai编程
桃西西呀1 天前
我把整本接口文档塞进 system prompt,前 3 轮答得准,第 8 轮开始胡说,账单还翻了 4 倍
人工智能·llm·ai编程
小郭哥x1 天前
Codex 桌面版(Windows)启动后无 UI 窗口问题
chatgpt·openai·codex
用户837133200761 天前
感觉终于把复杂的 RAG 技术整理明白了
人工智能·llm
自养Agent1 天前
Agent Harness 从用到会造:Skill 不是一次 API 调用,是一段会复用的行为
人工智能·llm