This directory contains example files demonstrating various use cases of the promptfmt library.
First, build the package:
npm run buildThen run examples using one of these methods:
# Install ts-node if not already installed
npm install -g ts-node
# Run an example
npx ts-node -r tsconfig-paths/register examples/01-basic-usage.ts
# Or run all examples
npx ts-node -r tsconfig-paths/register examples/run-all.ts# Build the package first
npm run build
# Examples import from src, so they need to be run with ts-node
# or you can modify imports to use '../dist' after buildingAfter installing the package, you can import and use it:
import { PromptBuilder } from 'promptfmt';
const prompt = new PromptBuilder()
.role('You are a helper')
.goal('Help users')
.build();Demonstrates the simplest way to use promptfmt with basic components (role, goal, input, output).
Shows how to use template strings with ${paramName} syntax and function-based dynamic content.
Demonstrates conditional logic to include/exclude components based on runtime parameters.
Shows how to control the order of components using the order option.
A sophisticated code review assistant that adapts based on programming language, code complexity, reviewer expertise level, and focus areas. Shows advanced conditional logic, dynamic content, and real-world complexity.
Demonstrates all available component types in a single prompt (role, goal, context, input, persona, tone, tasks, steps, few-shots, guardrails, constraints, output).
Shows how to use custom labels for components to create more structured and readable prompts.
Demonstrates using functions for dynamic content generation based on parameters.
Use ${paramName} in template strings:
.role('Hello ${name}')Use functions for dynamic content:
.role((params) => `Hello ${params.name}`)Include components conditionally:
.persona('Persona A', {
condition: createCondition(
(params) => params.age > 18,
new PersonaComponent('Adult Persona'),
new PersonaComponent('Child Persona')
)
})Control component order:
.role('Role', { order: 1 })
.goal('Goal', { order: 2 })Add custom labels:
.role('Role', { label: '🎭 ROLE' })