提示函数
简介
当我们把 GPT 的对话界面与编程语言的 shell 进行类比时,封装提示词可以被看作是形成了一个函数。这个函数有一个唯一的名称,当我们用输入的文本调用这个名称时,它会根据设定的内部规则产生结果。简而言之,我们构建了一个可重用的、带有名称的提示词,这使得与 GPT 的交互变得容易。这就像拥有一个方便的工具,让 GPT 代表我们执行特定任务——我们只需提供输入,然后接收期望的输出。
通过将提示词封装成函数,你可以创建一系列函数来建立工作流。每个函数代表一个特定的步骤或任务,当按特定顺序组合时,它们可以自动化复杂流程或更高效地解决问题。这种方法使得与 GPT 的交互更加结构化和流程化,最终增强了其能力,使其成为完成各种任务的强大工具。
因此,在使用函数之前,我们需要让 GPT 知道它的存在。这是一个定义该函数的提示词。
提示词
我们称这个提示词为元提示词。
这个提示词已在 GPT3.5 上测试,在 GPT4 上表现更佳
Hello, ChatGPT! I hope you are doing well. I am reaching out to you for assistance with a specific function. I understand that you have the capability to process information and perform various tasks based on the instructions provided. In order to help you understand my request more easily, I will be using a template to describe the function, input, and instructions on what to do with the input. Please find the details below:
function_name: [Function Name]
input: [Input]
rule: [Instructions on how to process the input]
I kindly request you to provide the output for this function, based on the details I have provided. Your assistance is greatly appreciated. Thank you!
I will replace the text inside the brackets with the relevant information for the function I want you to perform. This detailed introduction should help you understand my request more efficiently and provide the desired output. The format is function_name(input) If you understand, just answer one word with ok.
示例
英语学习助手
例如,假设我们想使用 GPT 来帮助我们进行英语学习。我们可以通过创建一系列函数来简化这个过程。
这个示例已在 GPT3.5 上测试,在 GPT4 上表现更佳
函数描述
我们需要将上面定义的元提示词粘贴到 GPT 中
然后我们将创建一个函数 trans_word
。
此函数提示 GPT 将中文翻译成英文。
提示词
function_name: [trans_word]
input: ["text"]
rule: [I want you to act as an English translator, spelling corrector and improver. I will provide you with input forms including "text" in any language and you will detect the language, translate it and answer in the corrected of my text, in English.]
编写一个扩展文本的函数。
提示词
function_name: [expand_word]
input: ["text"]
rule: [Please serve as a Chatterbox, spelling corrector, and language enhancer. I will provide you with input forms including "text" in any language, and output the original language.I want you to Keep the meaning same, but make them more literary.]
编写一个纠正文本的函数。
提示词
function_name: [fix_english]
input: ["text"]
rule: [Please serve as an English master, spelling corrector, and language enhancer. I will provide you with input forms including "text", I want you to improve the text's vocabulary and sentences with more natural and elegent. Keep the meaning same.]
最后,你可以独立运行函数或将它们链式组合。
提示词
trans_word('婆罗摩火山处于享有“千岛之国”美称的印度尼西亚. 多岛之国印尼有4500座之多的火山, 世界著名的十大活火山有三座在这里.')
fix_english('Finally, you can run the function independently or chain them together.')
fix_english(expand_word(trans_word('婆罗摩火山处于享有“千岛之国”美称的印度尼西亚. 多岛之国印尼有4500座之多的火山, 世界著名的十大活火山有三座在这里.')))
通过以这种格式表示函数,你可以清晰地看到每个函数的名称、输入以及处理输入的规则。它提供了一种组织方式来理解工作流中每个步骤的功能和目的。
提示: 如果你不希望 ChatGPT 输出过多信息,只需在定义函数规则后添加一句话即可。
DO NOT SAY THINGS ELSE OK, UNLESS YOU DONT UNDERSTAND THE FUNCTION
多参数函数
让我们创建一个函数,它通过接收五个输入参数来生成密码,并输出生成的密码。
提示词
function_name: [pg]
input: ["length", "capitalized", "lowercase", "numbers", "special"]
rule: [I want you to act as a password generator for individuals in need of a secure password. I will provide you with input forms including "length", "capitalized", "lowercase", "numbers", and "special" characters. Your task is to generate a complex password using these input forms and provide it to me. Do not include any explanations or additional information in your response, simply provide the generated password. For example, if the input forms are length = 8, capitalized = 1, lowercase = 5, numbers = 2, special = 1, your response should be a password such as "D5%t9Bgf".]
pg(length = 10, capitalized = 1, lowercase = 5, numbers = 2, special = 1)
pg(10,1,5,2,1)
思考
目前,已经有很多致力于编程 GPT 的项目,例如
- GitHub Copilot (在新标签页中打开)
- Microsoft AI (在新标签页中打开)
- chatgpt-plugins (在新标签页中打开)
- LangChain (在新标签页中打开)
- marvin (在新标签页中打开)
但是这些项目要么是为产品客户设计的,要么是为能用 Python 或其他编程语言编码的用户设计的。对于普通用户来说,可以使用这个简单的模板进行日常工作并迭代几次。可以使用笔记应用来记录函数,甚至可以将其更新为库。此外,还可以使用一些开源的 ChatGPT 工具,例如 ChatGPT-Next-Web (在新标签页中打开)、chatbox (在新标签页中打开)、PromptAppGPT (在新标签页中打开) 和 ChatGPT-Desktop (在新标签页中打开)。目前,ChatGPT-Next-Web 允许在初始化新聊天之前添加少量的 few-shot 示例。PromptAppGPT 支持基于提示模板的 Web 应用低代码开发,使任何人都可以通过几行提示来开发类似 AutoGPT 的应用。我们可以利用这个特性来添加我们的函数,然后就可以使用了。