LLMS (Lange Language Models) 및 AI 응용 프로그램 용 타입 스크립트에서 구조화 된 프롬프트를 생성하기위한 사용하기 쉬운 프롬프트 빌더.
이 프로젝트는 OpenAI, Anthropic, Google Gemini 등의 다양한 AI 모델과 호환되는 간단한 인터페이스를 통해 신속한 가독성과 유지 관리를 향상시키는 것을 목표로합니다. 또한 인류가 권장하는 XML 기반 프롬프트 구조를 사용하여 프롬프트 품질 및 모델 이해를 향상시킵니다.
원래 Dreamloom의 내부 요구를 충족시키기 위해 개발 된 우리는 더 넓은 커뮤니티에 혜택을주기 위해 열린 소스를 열었습니다. Github에 대한 개선 및 기타 피드백에 대한 귀하의 제안을 환영합니다.
Github의 프로젝트에 기여하십시오
이 프로젝트는 Anthropic의 Claude AI 모델에 선호되는 구조 인 XML 기반 프롬프트를 사용합니다. Anthropic의 문서에 따르면 프롬프트에서 XML 태그를 사용하는 몇 가지 장점이 있습니다.
Claude for Claude가 권장하지만 프롬프트 엔지니어링에 대한이 구조화 된 접근 방식은 다른 LLM 및 AI 모델과 함께 작업 할 때 매우 유익 할 수 있으며, 모델이 프롬프트에 대한 이해와 반응을 더 잘 대응하여보다 정확하고 유용하게 만듭니다.
NPM을 사용하여 Prompt-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는 MIT 라이센스에 따라 릴리스됩니다. 자세한 내용은 라이센스 파일을 참조하십시오.