ตัวสร้างพรอมต์ที่ใช้งานง่ายสำหรับการสร้างพรอมต์ที่มีโครงสร้างใน typeScript สำหรับโมเดลภาษาขนาดใหญ่ (LLMS) และแอปพลิเคชัน AI
โครงการนี้มีจุดมุ่งหมายเพื่อปรับปรุงความสามารถในการอ่านและการบำรุงรักษาที่รวดเร็วผ่านอินเทอร์เฟซที่เรียบง่ายเข้ากันได้กับโมเดล AI ต่าง ๆ จาก OpenAI, Manthropic, Google Gemini และอีกมากมาย นอกจากนี้ยังใช้โครงสร้างพรอมต์ที่ใช้ XML ที่แนะนำโดยมานุษยวิทยาเพื่อปรับปรุงคุณภาพและความเข้าใจแบบจำลอง
เดิมทีพัฒนาขึ้นเพื่อตอบสนองความต้องการภายในของ DreamLoom เราได้เปิดแหล่งข้อมูลเพื่อประโยชน์ของชุมชนที่กว้างขึ้น เรายินดีต้อนรับคำแนะนำของคุณสำหรับการปรับปรุงและข้อเสนอแนะอื่น ๆ เกี่ยวกับ GitHub
มีส่วนร่วมในโครงการใน GitHub
โครงการนี้ใช้พรอมต์ที่ใช้ XML ซึ่งเป็นโครงสร้างที่ต้องการสำหรับโมเดล Claude AI ของมานุษยวิทยา ตามเอกสารของมานุษยวิทยาการใช้แท็ก XML ในพรอมต์มีข้อดีหลายประการ:
ในขณะที่การแนะนำโดยมานุษยวิทยาสำหรับ Claude วิธีการที่มีโครงสร้างนี้เพื่อกระตุ้นการวิศวกรรมจะเป็นประโยชน์อย่างมากเมื่อทำงานกับรุ่น LLMs และ AI อื่น ๆ เช่นกันช่วยให้โมเดลเข้าใจและตอบสนองได้ดีขึ้นกับพรอมต์ของคุณทำให้พวกเขาแม่นยำและมีประโยชน์มากขึ้น
ติดตั้ง Prompt-EZ โดยใช้ NPM:
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 >
เรายินดีต้อนรับผลงาน! โปรดดูคู่มือการสนับสนุนของเราสำหรับรายละเอียดเพิ่มเติมเกี่ยวกับวิธีเริ่มต้น
Prompt-EZ ได้รับการปล่อยตัวภายใต้ใบอนุญาต MIT ดูไฟล์ใบอนุญาตสำหรับรายละเอียดเพิ่มเติม