1. 首页 >> ChatGPT教程 >>

ChatGPT最好实践

背景

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

chatgpt中文版 http://chatgpt.guigege.cn 

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

本文是ChatGPT使用最好实践系列第1篇 - 提供清晰且明确的指令(write clear instructions)。

GPT大模型其实不会读心术,需要你在提示词(prompt)里明确你的具体诉求,大模型才会提供最好的回答。

  • 如果大模型给的回答太长,你可以在prompt里告知它你想要更简短的回答。
  • 如果大模型给的回答过于简单,你可以在prompt里要求它提供专家水准一般的输出。
  • 如果大模型给的回答格式你不喜欢,你可以在prompt里告知大模型你想要的输出格式。

简而言之,GPT需要猜的东西越少,回答的效果越好。

接下来详细讲述6个具体的操作指引。

策略1:在prompt里提供细节

如果要让GPT给出你想要的结果,需要确保你的prompt里包括重要的细节,否则GPT模型需要猜想你想要的答案,那给出的结果就未必好了。

以下是一些具体示例,第一列为bad prompt,第二列为good prompt,大家可以对照感受下。

WorseBetter
How do I add numbers in Excel?How do I add up a row of dollar amounts in Excel? I want to do this automatically for a whole sheet of rows with all the totals ending up on the right in a column called "Total".
Who’s president?Who was the president of Mexico in 2021, and how frequently are elections held?
Write code to calculate the Fibonacci sequence.Write a TypeScript function to efficiently calculate the Fibonacci sequence. Comment the code liberally to explain what each piece does and why it's written that way.
Summarize the meeting notes.Summarize the meeting notes in a single paragraph. Then write a markdown list of the speakers and each of their key points. Finally, list the next steps or action items suggested by the speakers, if any.

策略2:指定模型需要扮演的角色

OpenAI的Chat Completions API的messages参数可以通过指定role为system来告知模型需要扮演的角色。

curlhttps://api.openai.com/v1/chat/completions\
-H"Content-Type:application/json"\
-H"Authorization:Bearer$OPENAI_API_KEY"\
-d'{
"model":"gpt⑶.5-turbo",
"messages":[
{
"role":"system",
"content":"Youareamathgenius."
},
{
"role":"user",
"content":"Hello!"
}
]
}'

例如,你希望GPT帮你做内容创作,创作的每段内容里包括最少一个笑话或俏皮的评论。

那system可以按以下示例设计:

SYSTEMWhen I ask for help to write something, you will reply with a document that contains at least one 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.

可以在这个链接里看效果:Open in Playground[1]

策略3:用分隔符来明确prompt的结构

分隔符可以方便大模型更精确辨认prompt里的区别组成部份,回答效果更好。

参考示例:

USERSummarize the text delimited by triple quotes with a haiku.
"""insert text here"""
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.
USERinsert first article here
insert second article here
SYSTEMYou will be provided with a thesis abstract and a suggested title for it. The thesis title should give the reader a good idea of the topic of the thesis but should also be eye-catching. If the title does not meet these criteria, suggest 5 alternatives.
USERAbstract: insert abstract here Title: insert title here

对一些很简单的任务,加分隔符前后效果可能不明显。

但是对一些复杂的任务,比如很长的的prompt,加分隔符可让GPT精确辨认到每部份的结构,回答效果会更好。

策略4:指定完本钱项任务需要的步骤

有些任务是可以分步拆解的,明确告知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 this text in one sentence with a prefix that says "Summary: ".

Step 2 - Translate the summary from Step 1 into Spanish, with a prefix that says "Translation: ".
USER"""insert text here"""

比如上面的例子,GPT的回答就会根据你的要求,第一步先输出summary,第二步再把summary翻译为西班牙语。

可以在这个链接里看效果:Open in Playground[2]

策略5:提供示例

有时候你希望GPT依照你想要的风格回答问题,但是这个风格又很难用明确的语言表述出来,就能够通过提供样例的方式给GPT,这类就叫 few-shot learning/prompting。

参考示例以下,你提供了一组样例,system里指定了模型要扮演的角色。

后续user的问题,模型就会依照你提供的样例的风格进行回答。

SYSTEMAnswer in a consistent style.
USERTeach me about patience.
ASSISTANTThe river that carves the deepest valley flows from a modest spring; the grandest symphony originates from a single note; the most intricate tapestry begins with a solitary thread.
USERTeach me about the ocean.

可以在这个链接里看效果:Open in Playground[3]

策略6:明确回答的长度

你可以告知模型回答内容的长度,这个长度可以是字数,可以是句子数量,也能够是段落数量等。对字数,模型不会特别精准。

参考示例以下:

USERSummarize the text delimited by triple quotes in about 50 words.
"""insert text here"""
USERSummarize the text delimited by triple quotes in 2 paragraphs.
"""insert text here"""
USERSummarize the text delimited by triple quotes in 3 bullet points.
"""insert text here"""

总结

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

知乎:无忌。

References

  • https://platform.openai.com/docs/guides/gpt-best-practices

参考资料

[1]

Open in Playground: https://platform.openai.com/playground/p/default-playful-thank-you-note

[2]

Open in Playground: https://platform.openai.com/playground/p/default-step-by-step-summarize-and-translate

[3]

Open in Playground: https://platform.openai.com/playground/p/default-chat-few-shot

[4]

GPT实战教程: https://github.com/jincheng9/gpt-tutorial

[5]

Jincheng's Blog: https://jincheng9.github.io/

桂,哥,网,络www.GuIgege.cn

本文来源于chatgptplus账号购买平台,转载请注明出处:https://chatgpt.guigege.cn/jiaocheng/37469.html 咨询请加VX:muhuanidc

联系我们

在线咨询:点击这里给我发消息

微信号:muhuanidc

工作日:9:30-22:30

X

截屏,微信识别二维码

微信号:muhuanidc

(点击微信号复制,添加好友)

打开微信

微信号已复制,请打开微信添加咨询详情!