Applications - Prompt Function

提示功能

前言

將提示(prompt)視為一種具名函數,不但能重複使用,也能串聯形成工作流程。這種方式讓 GPT 成為真正的任務助手,而非僅止於對話工具。


本篇目標


介紹

當我們將GPT的對話介面與程式語言的shell進行類比時,封裝提示(encapsulation prompt)可以被視為形成一個函數(function)。這個函數擁有一個獨特的名稱,當我們以輸入文字呼叫這個名稱時,它會根據內部設定的規則產生結果。簡單來說,我們建立了一個可重複使用的提示並給予其名稱,更容易與GPT互動。這就像擁有一項便利的工具,讓 GPT 能代表我們執行特定任務——我們只需提供輸入,就能獲得所需的輸出。

透過將提示封裝成函數,你可以建立一系列的函數來建立一個工作流程(workflow)。每個函數代表一個特定的步驟或任務,當它們以特定順序組合時,就能自動化複雜的流程或更有效地解決問題。這種方法使得與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輸出過多的信息,可以在定義函數的規則後簡單地添加一句話。

除非您不理解該功能,否則不要說其他任何話。

多個參數函式

讓我們創建一個函數,通過獲取5個輸入參數來生成密碼,並輸出生成的密碼。

提示:

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 程式設計,例如:

但這些項目要麼是為產品客戶設計的,要麼是為可以使用 Python 或其他程式設計語言進行編碼的用戶設計的。 對於普通使用者,請使用這個簡單的範本進行日常工作並反覆運算幾次。使用筆記應用程式來記錄該功能,甚至可以將其更新到庫中。 或者,一些開源 ChatGPT 工具,例如ChatGPT-Next-Web,聊天框,PromptAppGPTChatGPT-桌面,可以使用。目前,ChatGPT-Next-Web 允許在初始化新聊天之前添加一些鏡頭。PromptAppGPT 支援基於提示範本的 Web 應用程式的低程式碼開發,使任何人都可以通過幾行提示來開發類似 AutoGPT 的應用程式。 我們可以使用此功能來添加我們的函數,然後可以使用它。


References

Prompt Function


目錄 : Applications - 大型語言模型應用和指南

上一章:Applications - 畢業生職位分類專案研究
下一章:Prompt Hub - 提示詞匯集