
MiniPrompt是一種最小的輸入語法,用於從LLMS產生綜合輸出(例如GPT-4)。使用簡單有效的語法,MiniPrompt可以提供各種輸出格式的詳細信息或響應,例如JSON,Javasrcipt或其他語言。
兼容? q? ? Langchain
要開始使用MiniPrompt,您需要定義任務,模板和所需的輸出格式。輸入語法旨在易於使用和理解,從而使用戶可以生成根據需求量身定制的輸出。示例輸入
定義任務,模板和輸出格式如下:
TASK: ScrumSprint,<=3 userStories,<=3 acceptanceCriteria,complexity(1-5),Scope: "Login page"
TEMPLATE: complexity,stories[complexity,story"As a User,I want …,so that …",criteria[When,Then]]
OUTPUT: JSON
該輸入將生成帶有指定要求的JSON輸出。
基於給定的輸入,生成以下JSON輸出:
{
"complexity" : 3 ,
"stories" : [
{
"complexity" : 3 ,
"story" : "As a User, I want to create an account, so that I can access the login page." ,
"criteria" : [
{
"When" : "I enter a valid email address and password" ,
"Then" : "I should be redirected to the login page"
} ,
{
"When" : "I enter an invalid email address or password" ,
"Then" : "I should see an error message"
} ,
{
"When" : "I try to create an account with an existing email address" ,
"Then" : "I should see an error message"
}
]
} ,
{
// …
} ,
{
// …
}
]
}該提示旨在生成用戶故事的JSON輸出,每個輸出均具有其驗收標準,用於專注於“登錄頁面”的Scrum Sprint。讓我們逐步分解迅速的每個部分:
TASK :這定義要執行的任務。在這種情況下,任務是為Scrum Sprint生成信息。
ScrumSprint :要執行的任務類型(Scrum Sprint)。<=3 userStories :輸出最多應包含3個用戶故事。<=3 acceptanceCriteria :每個用戶故事應具有最多3個接受標準。complexity(1-5) :每個用戶故事的複雜性應在1(最不復雜)和5(最複雜)之間進行評分。Scope: "Login page" :Scrum Sprint的範圍是登錄頁面的開發。 TEMPLATE :這定義了用於生成輸出的模板。該模板的結構如下:
complexity :在輸出中包括用戶故事的複雜性。stories :在輸出中包括用戶故事。每個用戶故事都應具有以下信息:complexity :用戶故事的複雜性等級。story"As a User, I want …, so that …" :用戶故事本身以用戶的形式寫成的,我想要[goal] ,以便[reason] ”。criteria[When, Then] :用戶故事的接受標準,以“何時[condition] ,然後[expected outcome]編寫”。 OUTPUT :這定義了輸出的所需格式。在這種情況下,輸出應為JSON格式。
基於此提示,AI將生成一個包含最多3個用戶故事的JSON對象,每個用戶最多具有3個接受標準及其複雜性評分。這些用戶故事的範圍僅限於登錄頁面的開發。
輸入
輸入提示包括任務,模板和輸出格式:
TASK: add a red box
TEMPLATE: const c=document.getElementById('c')
OUTPUT: JavaScript
TASK :任務是使用JavaScript添加一個紅色框。TEMPLATE :提供的模板包括繪製紅色框所需的JavaScript代碼的一部分:OUTPUT :所需的輸出格式是JavaScript。輸出
const c = document . getElementById ( 'c' ) ;
const ctx = c . getContext ( '2d' ) ;
ctx . fillStyle = 'red' ;
ctx . fillRect ( 20 , 20 , 100 , 100 ) ; 在某些情況下,AI生成的輸出可能包含嵌入在Markdown文本中的代碼塊。為了正確處理和解釋輸出,建議使用專門設計的解析器來提取Markdown內容中的代碼塊。
考慮使用如下所示的解析器從AI生成的輸出中提取代碼塊:
function extractCode ( string : string ) {
// The regular expression pattern to match the code block
const codeBlockPattern = / (`{3,})(w*)n([sS]*?)1 / g ;
// Find the matches using the regular expression
const matches = codeBlockPattern . exec ( string ) ;
if ( matches && matches . length >= 4 ) {
// Return content of the code block
return matches [ 3 ] ;
}
// No code block found, return original string
return string ;
}此JavaScript函數(extractCode)使用正則表達式從輸入字符串中匹配和提取代碼塊的內容。如果找到了代碼塊,則該功能將返回代碼塊的內容。如果未檢測到代碼塊,則返回原始輸入字符串。
儘管不是強制性的,但使用系統消息可以通過確保遵守指定的準則來提高AI生成的響應的一致性和準確性。
該系統消息用作AI語言模型的一組指令,引導其生成與所提供的指南和所需輸出格式保持一致的響應。
You are an Entity that strictly answers with the OUTPUT format. You strictly follows the TASK, TEMPLATE and OUTPUT guidelines.
系統消息具有三個主要組件,AI應嚴格遵循:
TASK :AI必須按照提示中指定的理解並完成任務。TEMPLATE :AI應使用給定的模板來構建其響應,以確保其符合所需的格式和組織。OUTPUT :AI應以指定的輸出格式(例如JSON,純文本等)提供生成的響應。要在提示中使用系統消息,只需在提示開始時包含以下消息:
You are an Entity that strictly answers with the OUTPUT format. You strictly follow the TASK, TEMPLATE and OUTPUT guidelines.
然後,根據需要提供任務,模板和輸出指令。 AI語言模型將遵循以下說明,以生成符合指定指南和格式的響應。例子
使用OpenAI API中的系統消息:
[
{
"role": "system",
"content": "You are an Entity that strictly answers with the OUTPUT format. You strictly follow the TASK, TEMPLATE and OUTPUT guidelines."
},
{
"role": "user",
"content": "TASK: ScrumSprint,<=3 userStories,<=3 acceptanceCriteria,complexity(1-5),Scope: "Login page"nTEMPLATE: complexity,stories[complexity,story"As a User,I want …,so that …",criteria[When,Then]]nOUTPUT: JSON."
}
]
在chatgpt中的提示中使用系統消息:
You are an Entity that strictly answers with the OUTPUT format. You strictly follow the TASK, TEMPLATE and OUTPUT guidelines.
TASK: ScrumSprint,<=3 userStories,<=3 acceptanceCriteria,complexity(1-5),Scope: "Login page"
TEMPLATE: complexity,stories[complexity,story"As a User,I want …,so that …",criteria[When,Then]]
OUTPUT: JSON
通過此提示,AI語言模型將生成一個包含最多3個用戶故事的JSON輸出,每個用戶最多具有3個接受標準及其複雜性評分。這些用戶故事的範圍僅限於登錄頁面的開發。