易于使用的提示构建器,用于在打字稿中为大型语言模型(LLMS)和AI应用程序创建结构化提示。
该项目旨在通过简单的接口来提高及时的可读性和可维护性,与OpenAI,Anthropic,Google Gemini等的各种AI模型兼容。它还使用拟人化建议的基于XML的提示结构来提高及时的质量和模型理解。
我们最初开发的是为了满足Dreamloom的内部需求,我们已经开源了它,以使更广泛的社区受益。我们欢迎您提出有关GitHub的改进和其他反馈的建议。
在Github上为该项目做出贡献
该项目利用基于XML的提示,这是人类Claude AI模型的首选结构。根据Anthropic的文档,在提示中使用XML标签提供了几个优点:
虽然通过拟人化为克劳德(Claude)推荐,但在与其他LLMS和AI模型合作时,这种结构化的促进工程方法可能非常有益,可以帮助模型对您的提示更好地理解和响应,从而使它们更加准确和有用。
使用NPM安装提示-EZ:
npm install prompt-ez
PromptBuilder
类是用于创建结构化提示的主要接口。这是其方法的快速概述:
tag(name: string, contentFn?: (builder: PromptBuilder) => void): PromptBuilder
name
:标签的名称。contentFn
:可选功能以在标签中添加内容。 text(text: string): PromptBuilder
list(items: string[]): PromptBuilder
inputs(): PromptBuilder
build(params?: Record<string, unknown>): string
params
:具有动态输入的键值对的可选对象。这是创建结构化提示的一个简单示例:
import PromptBuilder from 'prompt-ez' ;
const prompt = new PromptBuilder ( )
. tag ( 'system' , b => b
. text ( 'You are a helpful AI assistant.' )
. text ( 'Please provide accurate and concise information.' )
)
. tag ( 'task' , b => b
. text ( 'Explain the benefits of regular exercise.' )
)
. tag ( 'output_format' , b => b
. text ( 'Provide the explanation in a paragraph.' )
)
. build ( ) ;
console . log ( prompt ) ;
这会生成以下提示:
< system >
You are a helpful AI assistant.
Please provide accurate and concise information.
</ system >
< task >
Explain the benefits of regular exercise.
</ task >
< output_format >
Provide the explanation in a paragraph.
</ output_format >
这是在您的提示中使用动态输入的方法:
const promptWithInputs = new PromptBuilder ( )
. tag ( 'system' , b => b
. text ( 'You are a language translator.' )
)
. tag ( 'task' , b => b
. text ( 'Translate the following text:' )
. inputs ( )
)
. build ( {
source_language : 'English' ,
target_language : 'French' ,
text : 'Hello, how are you?'
} ) ;
console . log ( promptWithInputs ) ;
这会产生:
< system >
You are a language translator.
</ system >
< task >
Translate the following text:
< source_language >English</ source_language >
< target_language >French</ target_language >
< text >Hello, how are you?</ text >
</ task >
这是一个更复杂的示例,演示了嵌套标签,列表创建和动态输入:
import PromptBuilder from 'prompt-ez' ;
export const AI_MEDICAL_DIAGNOSIS_PROMPT = new PromptBuilder ( )
. tag ( 'medical_diagnosis_prompt' , ( builder ) =>
builder
. tag ( 'role' , ( b ) => b . text ( 'Act as an AI medical assistant. Analyze the provided patient information and suggest three potential diagnoses with recommended next steps.' ) )
. inputs ( )
. tag ( 'guidelines' , ( b ) =>
b
. text ( 'For each potential diagnosis:' )
. list ( [
'Consider the patient's symptoms, medical history, and test results' ,
'Provide a brief explanation of the condition' ,
'List key symptoms that align with the diagnosis' ,
'Suggest additional tests or examinations if needed' ,
'Outline potential treatment options' ,
'Indicate the urgency level (e.g., immediate attention, routine follow-up)' ,
'Highlight any lifestyle changes or preventive measures' ,
'Consider possible complications if left untreated' ,
'Use medical terminology appropriately, with layman explanations' ,
'Provide a confidence level for each diagnosis (low, medium, high)' ,
'First analyze the information thoroughly, then produce the output'
] )
)
. tag ( 'reminder' , ( b ) => b . text ( 'Ensure the diagnoses are evidence-based and consider a range of possibilities from common to rare conditions. Always emphasize the importance of consulting with a human healthcare professional for a definitive diagnosis.' ) )
. tag ( 'output_format' , ( b ) =>
b . list ( [
'Present information in a clear, structured manner' ,
'Use bullet points for symptoms and recommendations' ,
'Include relevant medical terms with brief explanations' ,
'Provide a summary of each potential diagnosis' ,
'Suggest follow-up questions to gather more information if needed' ,
'End with a disclaimer about the limitations of AI diagnosis'
] )
)
)
. build ( {
patient_age : 45 ,
patient_gender : 'Female' ,
main_symptoms : 'Persistent headache, blurred vision, and occasional dizziness for the past two weeks' ,
medical_history : 'Hypertension, controlled with medication' ,
recent_tests : 'Blood pressure: 150/95 mmHg, Blood sugar: 110 mg/dL (fasting)'
} ) ;
console . log ( AI_MEDICAL_DIAGNOSIS_PROMPT ) ;
这将产生一个复杂的结构化提示,以实现AI医学诊断情况:
< medical_diagnosis_prompt >
< role >Act as an AI medical assistant. Analyze the provided patient information and suggest three potential diagnoses with recommended next steps.</ role >
< patient_age >45</ patient_age >
< patient_gender >Female</ patient_gender >
< main_symptoms >Persistent headache, blurred vision, and occasional dizziness for the past two weeks</ main_symptoms >
< medical_history >Hypertension, controlled with medication</ medical_history >
< recent_tests >Blood pressure: 150/95 mmHg, Blood sugar: 110 mg/dL (fasting)</ recent_tests >
< guidelines >
For each potential diagnosis:
1. Consider the patient's symptoms, medical history, and test results
2. Provide a brief explanation of the condition
3. List key symptoms that align with the diagnosis
4. Suggest additional tests or examinations if needed
5. Outline potential treatment options
6. Indicate the urgency level (e.g., immediate attention, routine follow-up)
7. Highlight any lifestyle changes or preventive measures
8. Consider possible complications if left untreated
9. Use medical terminology appropriately, with layman explanations
10. Provide a confidence level for each diagnosis (low, medium, high)
11. First analyze the information thoroughly, then produce the output
</ guidelines >
< reminder >Ensure the diagnoses are evidence-based and consider a range of possibilities from common to rare conditions. Always emphasize the importance of consulting with a human healthcare professional for a definitive diagnosis.</ reminder >
< output_format >
1. Present information in a clear, structured manner
2. Use bullet points for symptoms and recommendations
3. Include relevant medical terms with brief explanations
4. Provide a summary of each potential diagnosis
5. Suggest follow-up questions to gather more information if needed
6. End with a disclaimer about the limitations of AI diagnosis
</ output_format >
</ medical_diagnosis_prompt >
我们欢迎捐款!请参阅我们的贡献指南,以获取有关如何入门的更多详细信息。
提示-EZ根据麻省理工学院许可发布。有关更多详细信息,请参见许可证文件。