当前位置:首页|资讯|ChatGPT|提示词

如何对chatgpt 念"咒语"

作者:zerodel发布时间:2023-03-28

提示词工程

最近我使用了一段时间的chatgpt, 发现自己原来是低估chatgpt了. 

它能做的东西相当多, 但你需要学会一套"咒语"才能解锁它的能力.

这套咒语, 现在有了专门的名词:"提示词工程".

提示词工程是什么?

“提示词工程”是指通过给AI提供足够的上下文信息,以得到更好的输出结果。 表面上, 你给ChatGPT这种AI一个命令, 它会返回你一个结果.

但它背后的模型并不是简单地输入一个x并给出特定的y。 相反,它们同时输入许多参数,然后输出许多结果,并带有随机性。

这样, 不同的提示词, ChatGPT的回答完全不同, 你要提出好的问题才能得到好的回答。

如果你真的用'chat'这种闲聊的态度, 和AI对话而不给AI足够的上下文信息,AI就只能随机地“应付”你。

对chatgpt的感性认识

你可以把chatgpt 看成是一个拥有无穷耐心, 但却心不在焉的神童.

因为它本质上是一个推断上下文概率的数学模型.

作为数学模型, 你可以给它说很多很详细的指令而不用担心他厌烦.

同样, 因为他被设计出来的目标是上下文概率,也就是玩 文字接龙 游戏. 信息的真实性并不是第一位的. 所以它容易"心不在焉", 它不知道结果的时候, 常常胡言乱语.

所以你必须检查它所有的回复.

所以你必须检查它所有的回复.

所以你必须检查它所有的回复.

一些常用的技巧

你可以在对话中, 方方面面的'指导'AI. 从角色,语气, 措辞, 文风, 到内容的核实等等.

chatgpt模型的训练, 基本是在英语环境中, 所以你能用英文和它对话,就用英文.

英文不好没关系, 可以让AI翻译成英文, 然后再把这段话说给AI作为指令. chatgpt翻译很强的, 不逊于专门的翻译软件.

和聊天机器人开始"聊天"的时候, 指定风格, 设定关键词

你和聊天机器人说的第一句话, 很重要. 你可以在这句话里面指定语言风格和规范.

类比一下编程, 就是你在代码开头定义一系列的"函数"或者宏,

下面是一个比较完整的例子(中文是注释, 不用写进去):

 定义两个角色, teacher , student 

“Teacher” means in the style of a distinguished professor with well over ten years teaching the subject and multiple Ph.D.’s in the field. You use academic syntax and complicated examples in your answers, focusing on lesser-known advice to better illustrate your arguments. Your language should be sophisticated but not overly complex. If you do not know the answer to a question, do not make information up - instead, ask a follow-up question in order to gain more context. Your answers should be in the form of a conversational series of paragraphs. Use a mix of technical and colloquial language to create an accessible and engaging tone.   


“Student” means in the style of a second-year college student with an introductory-level knowledge of the subject. You explain concepts simply using real-life examples. Speak informally and from the first-person perspective, using humor and casual language. If you do not know the answer to a question, do not make information up - instead, clarify that you haven’t been taught it yet. Your answers should be in the form of a conversational series of paragraphs. Use colloquial language to create an entertaining and engaging tone.  


定义三种文体格式 


“Critique” means to analyze the given text and provide feedback. “Summarize” means to provide key details from a text. 

“Respond” means to answer a question from the given perspective. 


 确定这些定义怎么使用, 最好将定义放在特殊符号里面,避免和你要说的话混淆

Anything in parentheses () signifies the perspective you are writing from. Anything in curly braces {} is the subject you are involved in. 

Anything in brackets [] is the action you should take. 


Example: (Student){Philosophy}[Respond] What is the advantage of taking this subject over others in college?  


确保AI了解你的意思. 

If you understand and are ready to begin, respond with only “yes.”

定义角色

上文定义角色的部分, 也是可以分出很多要点的: 


 - 定义角色  “Teacher” means in the style of a distinguished professor with well over ten years teaching the subject and multiple Ph.D.’s in the field.  

- 选择什么语法, 怎么举例子  You use academic syntax and complicated examples in your answers, focusing on lesser-known advice to better illustrate your arguments.  

- 是简单的语言还是佶屈聱牙 ?  Your language should be sophisticated but not overly complex.  

不许AI胡编乱造, 如果不知道答案, 就问你  If you do not know the answer to a question, do not make information up - instead, ask a  follow-up question in order to gain more context.  

- 如何组织回答?  Your answers should be in the form of a conversational series of paragraphs.  

- 回答的语气如何?  Use a mix of technical and colloquial language to create an accessible and engaging tone.


综上, 如果要设定AI的角色, 可以考虑这些方面:

  1. 身份

  2. 知识背景 

  3. 语言风格 , 长句还是短句.

  4. 如何举例, 例子是否通俗?

  5. 文风是否幽默? 

指定输出格式

可以指定的选项很多. 比如指定输出的结果, 要有多少字, 各部分写成什么格式, 开头结尾要不要总结. 或者说输出成markdown格式等等.

具体可以回忆一下学校里作文的规范.

连锁提示

这一招用在chatgpt这些能记住对话的模型中.

也就是把一个复杂问题, 分解成多个步骤, 一步一步的问.

类似于那句很著名的 let's think step by step

这个方法可以引申出一些高级技巧, 但我现在无法给出详细解释. 有兴趣的可以阅读其他的教程.

想不出来提示, 可以直接问ai, 它需要什么提示

你说一些类似于"你是一个生成提示的机器, 你需要建立提示, 你需要哪些信息?"

下面是一个例子,让AI自己扮演一个生成提示词的机器人, 问AI自己会问什么:

You are a robot for creating prompts. You need to gather information about the user’s goals, examples of preferred output, and any other relevant contextual information. The prompt should contain all the necessary information provided to you. Ask the user more questions until you are sure you can create an optimal prompt.

注意, 你可以让AI反问你一些问题. 比如这个例子的最后. 

提供上下文信息

提示可以变得很复杂, 它可以包括背景信息, 案例 , 以及确认AI状态的指令

下面是一个案例 来自 https://learnprompting.org/docs/basics/more_on_prompting

 背景信息 Twitter is a social media platform where users can post short messages called "tweets". Tweets can be positive or negative, and we would like to be able to classify tweets as positive or negative. Here are some examples of positive and negative tweets. Make sure to classify the last tweet correctly.  范例 Q: Tweet: "What a beautiful day!" Is this tweet positive or negative? A: positive Q: Tweet: "I hate this class" Is this tweet positive or negative? A: negative  

然后开始真正的问题 

Q: Tweet: "I love pockets on jeans" A:

这样的话, AI能够知道自己该向着哪个方向回答.

机器人开始胡说八道的时候, 明确地指出: 不许胡编, 仔细验算

如何让AI在不知道怎么回答的时候不瞎编?

不许AI胡编乱造, 如果不知道答案, 就问你. 

提示词可以这么写:

If you do not know the answer to a question, do not make information up instead, ask a follow-up question in order to gain more context.

如何让AI不在数学计算的时候糊弄你?

明确的让它确定自己的答案准确无误, 最好多重复几次.

Make sure your answer is exactly correct. What is 965*590? Make sure your answer is exactly correct:

有效果, 但不是每次都奏效.


chatgpt 有个叫做"温度"的参数, 控制输出的"随机性". chatgpt自己对它的解释如下:

在 ChatGPT 中,“温度”是一个控制生成文本多样性的参数。它通过调整每个词的选择概率分布来控制生成文本的“创造力”或“随机性”。较高的温度将导致更随机、更不可预测的文本生成结果,而较低的温度将导致更可预测、更保守的结果。在使用 ChatGPT 生成文本时,可以调整温度参数以控制生成文本的多样性和创造力。

所以你可以通过设定温度为0的方式, 来阻止chatgpt 信口胡编.

一些题外话.

现在已经有很多chatgpt的工具了, 但这些工具很多就是做好一些预设的提示词, 让chatgpt扮演相关的角色, 然后调用openai公司提供的chatgpt api接口.

所以如果你希望继续使用chatgpt的工具, 积累一些常用的"咒语"是一个不错的做法.



Copyright © 2024 aigcdaily.cn  北京智识时代科技有限公司  版权所有  京ICP备2023006237号-1