
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个接受标准及其复杂性评分。这些用户故事的范围仅限于登录页面的开发。