### Install prompt-ez using npm Source: https://github.com/dreamloom-ai/prompt-ez/blob/master/README.md This command installs the prompt-ez package from npm. Ensure you have Node.js and npm or yarn installed on your system. ```bash npm install prompt-ez ``` -------------------------------- ### Basic Prompt Creation in TypeScript Source: https://github.com/dreamloom-ai/prompt-ez/blob/master/README.md Demonstrates the creation of a structured prompt using the PromptBuilder class. This example shows how to define system instructions, a task, and an output format using nested tags. The resulting prompt is a string. ```typescript 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); ``` -------------------------------- ### Create Basic Structured Prompt with XML Tags in TypeScript Source: https://context7.com/dreamloom-ai/prompt-ez/llms.txt Demonstrates building a simple prompt using the PromptBuilder class with nested XML tags. This example shows how to define system instructions, tasks, and output formats using a fluent API, resulting in a structured prompt string. ```typescript 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); /* Output: You are a helpful AI assistant. Please provide accurate and concise information. Explain the benefits of regular exercise. Provide the explanation in a paragraph. */ ``` -------------------------------- ### Inject Dynamic Inputs into Prompts with Parameters in TypeScript Source: https://context7.com/dreamloom-ai/prompt-ez/llms.txt Illustrates how to create flexible and reusable prompt templates by injecting dynamic values using parameters at build time. This example shows a translation prompt where source language, target language, text, and context are provided as inputs. ```typescript import PromptBuilder from 'prompt-ez'; const translationPrompt = new PromptBuilder() .tag('system', b => b .text('You are a professional language translator.') ) .tag('task', b => b .text('Translate the following text:') .inputs() ) .build({ source_language: 'English', target_language: 'French', text: 'Hello, how are you?', context: 'casual conversation' }); console.log(translationPrompt); /* Output: You are a professional language translator. Translate the following text: English French Hello, how are you? casual conversation */ ``` -------------------------------- ### Generate Numbered Lists within Prompts Using TypeScript Source: https://context7.com/dreamloom-ai/prompt-ez/llms.txt Shows how to generate structured, numbered lists within prompts using the `list()` method of the PromptBuilder. This example creates a code review prompt with specific instructions presented as a numbered list. ```typescript import PromptBuilder from 'prompt-ez'; const codeReviewPrompt = new PromptBuilder() .tag('role', b => b .text('You are a senior software engineer conducting a code review.') ) .tag('instructions', b => b .text('When reviewing code, focus on:') .list([ 'Code readability and maintainability', 'Performance optimizations', 'Security vulnerabilities', 'Best practices and design patterns', 'Test coverage and edge cases' ]) ) .tag('output', b => b .text('Provide specific feedback with line references.') ) .build(); console.log(codeReviewPrompt); /* Output: You are a senior software engineer conducting a code review. When reviewing code, focus on: 1. Code readability and maintainability 2. Performance optimizations 3. Security vulnerabilities 4. Best practices and design patterns 5. Test coverage and edge cases Provide specific feedback with line references. */ ``` -------------------------------- ### Reusable Prompt Templates with Prompt-Ez Source: https://context7.com/dreamloom-ai/prompt-ez/llms.txt Shows how to create reusable prompt templates using a class-based approach. This allows for instantiating complex prompts with different parameters, promoting code reuse and consistency. ```typescript import PromptBuilder from 'prompt-ez'; // Define a reusable template class EmailGeneratorTemplate { static create(params: { recipient_name: string; email_type: string; key_points: string[]; tone?: string; }) { return new PromptBuilder() .tag('email_generation', b => b .tag('role', r => r .text('You are a professional email writer.') ) .tag('task', t => t .text('Generate a professional email with the following details:') .inputs() ) .tag('requirements', req => req .list([ 'Use appropriate greeting and closing', 'Maintain professional tone throughout', 'Keep the email concise and focused', 'Include all key points naturally', 'Proofread for grammar and clarity' ]) ) ) .build({ recipient_name: params.recipient_name, email_type: params.email_type, key_points: params.key_points, tone: params.tone || 'professional' }); } } // Use the template const followUpEmail = EmailGeneratorTemplate.create({ recipient_name: 'John Smith', email_type: 'Follow-up after meeting', key_points: [ 'Thank for their time', 'Summarize action items', 'Propose next meeting date' ], tone: 'friendly yet professional' }); console.log(followUpEmail); /* Output: You are a professional email writer. Generate a professional email with the following details: John Smith Follow-up after meeting ["Thank for their time","Summarize action items","Propose next meeting date"] friendly yet professional 1. Use appropriate greeting and closing 2. Maintain professional tone throughout 3. Keep the email concise and focused 4. Include all key points naturally 5. Proofread for grammar and clarity */ ``` -------------------------------- ### Build Complex Nested Prompt with Arrays and Objects (TypeScript) Source: https://context7.com/dreamloom-ai/prompt-ez/llms.txt Demonstrates creating a deeply nested prompt structure using Prompt-Builder. It includes tags with text content, lists, and dynamic inputs resolved from an object containing arrays and nested objects. Dependencies include the 'prompt-ez' library. The output is a structured XML-like string representing the prompt. ```typescript import PromptBuilder from 'prompt-ez'; const dataAnalysisPrompt = new PromptBuilder() .tag('analysis_prompt', builder => builder .tag('role', b => b .text('Act as a data scientist analyzing customer feedback.') ) .inputs() .tag('analysis_steps', b => b .text('Perform the following analysis:') .list([ 'Identify common themes and sentiment patterns', 'Calculate sentiment scores for each feedback item', 'Categorize feedback into topics', 'Highlight urgent issues requiring immediate attention', 'Provide actionable recommendations' ]) ) .tag('output_format', b => b .list([ 'Summary statistics', 'Top 5 themes with examples', 'Sentiment distribution chart data', 'Priority recommendations' ]) ) ) .build({ dataset_name: 'Q4 Customer Feedback', feedback_items: ['Great product!', 'Shipping was slow', 'Excellent customer service'], analysis_parameters: { min_confidence: 0.7, include_neutral: false }, previous_insights: [] // Empty array filtered out }); console.log(dataAnalysisPrompt); /* Output: Act as a data scientist analyzing customer feedback. Q4 Customer Feedback ["Great product!","Shipping was slow","Excellent customer service"] {"min_confidence":0.7,"include_neutral":false} Perform the following analysis: 1. Identify common themes and sentiment patterns 2. Calculate sentiment scores for each feedback item 3. Categorize feedback into topics 4. Highlight urgent issues requiring immediate attention 5. Provide actionable recommendations 1. Summary statistics 2. Top 5 themes with examples 3. Sentiment distribution chart data 4. Priority recommendations */ ``` -------------------------------- ### Filtering Empty and Null Values in Prompt-Ez Build() Source: https://context7.com/dreamloom-ai/prompt-ez/llms.txt Demonstrates how the build() method in Prompt-Ez automatically filters out various empty or null values, including empty strings, null, undefined, empty arrays, and empty objects, while retaining valid data. ```typescript import PromptBuilder from 'prompt-ez'; const promptWithFiltering = new PromptBuilder() .tag('analysis', b => b .text('Analyze the following data:') .inputs() ) .build({ valid_string: 'This will appear', valid_number: 42, valid_boolean: true, empty_string: '', // Filtered out null_value: null, // Filtered out undefined_value: undefined, // Filtered out empty_array: [], // Filtered out empty_object: {}, // Filtered out valid_array: [1, 2, 3], // Included valid_object: { key: 'value' } // Included }); console.log(promptWithFiltering); /* Output: Analyze the following data: This will appear 42 true [1,2,3] {"key":"value"} */ ``` -------------------------------- ### Medical Diagnosis Prompt Generation with PromptBuilder (TypeScript) Source: https://context7.com/dreamloom-ai/prompt-ez/llms.txt This TypeScript code utilizes the PromptBuilder library to construct a detailed prompt for an AI medical assistant. It defines the AI's role, input parameters (patient data), diagnostic guidelines, reminders, and the desired output format. The generated prompt is then printed to the console. ```typescript import PromptBuilder from 'prompt-ez'; const medicalDiagnosisPrompt = 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)', medications: ['Lisinopril 10mg daily'] }); console.log(medicalDiagnosisPrompt); /* Output: Act as an AI medical assistant. Analyze the provided patient information and suggest three potential diagnoses with recommended next steps. 45 Female Persistent headache, blurred vision, and occasional dizziness for the past two weeks Hypertension, controlled with medication Blood pressure: 150/95 mmHg, Blood sugar: 110 mg/dL (fasting) ["Lisinopril 10mg daily"] 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 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. 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 */ ``` -------------------------------- ### Error Handling for Missing Inputs() Call in Prompt-Ez Source: https://context7.com/dreamloom-ai/prompt-ez/llms.txt This snippet illustrates how to correctly handle errors that occur when parameters are provided to the PromptBuilder without first calling the inputs() method. It shows both the incorrect usage that leads to an error and the proper implementation. ```typescript import PromptBuilder from 'prompt-ez'; try { // This will throw an error because inputs() was not called const invalidPrompt = new PromptBuilder() .tag('task', b => b .text('Process this data') ) .build({ data: 'some value' }); } catch (error) { console.error(error.message); // Output: "Inputs were provided but inputs() was not called in the prompt builder." } // Correct usage: const validPrompt = new PromptBuilder() .tag('task', b => b .text('Process this data') .inputs() ) .build({ data: 'some value' }); console.log(validPrompt); /* Output: Process this data some value */ ``` -------------------------------- ### TypeScript: Build Prompt with Dynamic Inputs Source: https://github.com/dreamloom-ai/prompt-ez/blob/master/README.md Constructs a prompt with dynamic inputs for language translation. It uses the PromptBuilder class to define system and task tags, injecting input values at runtime. The output is the fully constructed prompt string. ```typescript 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); ``` -------------------------------- ### XML: Prompt Output with Dynamic Inputs Source: https://github.com/dreamloom-ai/prompt-ez/blob/master/README.md Represents the XML structure generated by the PromptBuilder when using dynamic inputs. It shows how the input variables are embedded within the respective tags of the prompt. ```xml You are a language translator. Translate the following text: English French Hello, how are you? ``` -------------------------------- ### Generated Medical Diagnosis Prompt (XML) Source: https://github.com/dreamloom-ai/prompt-ez/blob/master/README.md This XML output represents the structured prompt generated by the TypeScript code. It encapsulates the medical diagnosis request with detailed instructions, patient information, and formatting guidelines for an AI. ```xml Act as an AI medical assistant. Analyze the provided patient information and suggest three potential diagnoses with recommended next steps. 45 Female Persistent headache, blurred vision, and occasional dizziness for the past two weeks Hypertension, controlled with medication Blood pressure: 150/95 mmHg, Blood sugar: 110 mg/dL (fasting) 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 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. 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 ``` -------------------------------- ### Generate Medical Diagnosis Prompt (TypeScript) Source: https://github.com/dreamloom-ai/prompt-ez/blob/master/README.md This TypeScript code uses the prompt-ez library to construct a sophisticated prompt for an AI medical assistant. It defines roles, guidelines, and output formats, incorporating dynamic patient data to generate a structured medical analysis prompt. ```typescript 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); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.