易於使用的提示構建器,用於在打字稿中為大型語言模型(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根據麻省理工學院許可發布。有關更多詳細信息,請參見許可證文件。