Spaces:
Configuration error
Configuration error
| /** | |
| * Structured Prompting Frameworks | |
| * Pre-built templates to help users write better prompts | |
| */ | |
| export interface Framework { | |
| id: string | |
| name: string | |
| description: string | |
| sections: FrameworkSection[] | |
| example?: string | |
| } | |
| export interface FrameworkSection { | |
| id: string | |
| label: string | |
| description: string | |
| placeholder: string | |
| required: boolean | |
| } | |
| export const FRAMEWORKS: Record<string, Framework> = { | |
| RACE: { | |
| id: 'RACE', | |
| name: 'RACE', | |
| description: 'Role, Action, Context, Expectation - Clear structure for task-based prompts', | |
| sections: [ | |
| { | |
| id: 'role', | |
| label: 'Role', | |
| description: 'What role should the AI take?', | |
| placeholder: 'e.g., "You are a senior software engineer..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'action', | |
| label: 'Action', | |
| description: 'What should the AI do?', | |
| placeholder: 'e.g., "Review this code and suggest improvements..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'context', | |
| label: 'Context', | |
| description: 'What background information is relevant?', | |
| placeholder: 'e.g., "This is a React component for a production app..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'expectation', | |
| label: 'Expectation', | |
| description: 'What format/style do you want?', | |
| placeholder: 'e.g., "Provide feedback as a bulleted list..."', | |
| required: true, | |
| }, | |
| ], | |
| example: 'You are a senior software engineer. Review this code and suggest improvements. This is a React component for a production app with 10K users. Provide feedback as a bulleted list with code examples.', | |
| }, | |
| CARE: { | |
| id: 'CARE', | |
| name: 'CARE', | |
| description: 'Context, Action, Result, Example - Perfect for generating content', | |
| sections: [ | |
| { | |
| id: 'context', | |
| label: 'Context', | |
| description: 'Set the scene', | |
| placeholder: 'e.g., "I run a B2B SaaS startup..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'action', | |
| label: 'Action', | |
| description: 'What to create', | |
| placeholder: 'e.g., "Write a blog post about..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'result', | |
| label: 'Result', | |
| description: 'Desired outcome', | |
| placeholder: 'e.g., "Should be 1000 words, SEO optimized..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'example', | |
| label: 'Example', | |
| description: 'Show what good looks like', | |
| placeholder: 'e.g., "Similar to this style: [link]"', | |
| required: false, | |
| }, | |
| ], | |
| }, | |
| APE: { | |
| id: 'APE', | |
| name: 'APE', | |
| description: 'Action, Purpose, Expectation - Simple and effective', | |
| sections: [ | |
| { | |
| id: 'action', | |
| label: 'Action', | |
| description: 'What to do', | |
| placeholder: 'e.g., "Generate 10 headline ideas..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'purpose', | |
| label: 'Purpose', | |
| description: 'Why you need it', | |
| placeholder: 'e.g., "For a product launch email campaign..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'expectation', | |
| label: 'Expectation', | |
| description: 'Format and style', | |
| placeholder: 'e.g., "Short, punchy, under 60 characters..."', | |
| required: true, | |
| }, | |
| ], | |
| }, | |
| CREATE: { | |
| id: 'CREATE', | |
| name: 'CREATE', | |
| description: 'Character, Request, Examples, Adjustments, Type, Extras - Most comprehensive', | |
| sections: [ | |
| { | |
| id: 'character', | |
| label: 'Character', | |
| description: 'AI persona', | |
| placeholder: 'e.g., "Expert marketing copywriter..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'request', | |
| label: 'Request', | |
| description: 'Main task', | |
| placeholder: 'e.g., "Write ad copy for..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'examples', | |
| label: 'Examples', | |
| description: 'Sample outputs', | |
| placeholder: 'e.g., "Like this: [example]"', | |
| required: false, | |
| }, | |
| { | |
| id: 'adjustments', | |
| label: 'Adjustments', | |
| description: 'Constraints', | |
| placeholder: 'e.g., "Max 150 characters, casual tone..."', | |
| required: false, | |
| }, | |
| { | |
| id: 'type', | |
| label: 'Type', | |
| description: 'Output format', | |
| placeholder: 'e.g., "Bulleted list, JSON, table..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'extras', | |
| label: 'Extras', | |
| description: 'Additional notes', | |
| placeholder: 'e.g., "Focus on benefits not features..."', | |
| required: false, | |
| }, | |
| ], | |
| }, | |
| RISEN: { | |
| id: 'RISEN', | |
| name: 'RISEN', | |
| description: 'Role, Instructions, Steps, End goal, Narrowing - For complex tasks', | |
| sections: [ | |
| { | |
| id: 'role', | |
| label: 'Role', | |
| description: 'AI identity', | |
| placeholder: 'e.g., "Professional business consultant..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'instructions', | |
| label: 'Instructions', | |
| description: 'High-level guidance', | |
| placeholder: 'e.g., "Analyze this business plan..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'steps', | |
| label: 'Steps', | |
| description: 'Break it down', | |
| placeholder: 'e.g., "1. Review financials, 2. Assess market..."', | |
| required: false, | |
| }, | |
| { | |
| id: 'endGoal', | |
| label: 'End Goal', | |
| description: 'Success criteria', | |
| placeholder: 'e.g., "Provide actionable recommendations..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'narrowing', | |
| label: 'Narrowing', | |
| description: 'Scope limits', | |
| placeholder: 'e.g., "Focus only on Q4 2025..."', | |
| required: false, | |
| }, | |
| ], | |
| }, | |
| RTF: { | |
| id: 'RTF', | |
| name: 'RTF', | |
| description: 'Role, Task, Format - Quick and simple', | |
| sections: [ | |
| { | |
| id: 'role', | |
| label: 'Role', | |
| description: 'Who is the AI?', | |
| placeholder: 'e.g., "You are a helpful assistant..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'task', | |
| label: 'Task', | |
| description: 'What to do', | |
| placeholder: 'e.g., "Summarize this article..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'format', | |
| label: 'Format', | |
| description: 'How to present', | |
| placeholder: 'e.g., "5 bullet points, max 20 words each..."', | |
| required: true, | |
| }, | |
| ], | |
| }, | |
| TAG: { | |
| id: 'TAG', | |
| name: 'TAG', | |
| description: 'Task, Action, Goal - Minimal but effective', | |
| sections: [ | |
| { | |
| id: 'task', | |
| label: 'Task', | |
| description: 'What needs doing', | |
| placeholder: 'e.g., "Write product description..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'action', | |
| label: 'Action', | |
| description: 'Specific steps', | |
| placeholder: 'e.g., "Highlight key features and benefits..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'goal', | |
| label: 'Goal', | |
| description: 'Success metric', | |
| placeholder: 'e.g., "Convert visitors to customers..."', | |
| required: true, | |
| }, | |
| ], | |
| }, | |
| BAB: { | |
| id: 'BAB', | |
| name: 'BAB', | |
| description: 'Before, After, Bridge - For transformation stories', | |
| sections: [ | |
| { | |
| id: 'before', | |
| label: 'Before', | |
| description: 'Current state', | |
| placeholder: 'e.g., "Customer struggles with..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'after', | |
| label: 'After', | |
| description: 'Desired state', | |
| placeholder: 'e.g., "Customer achieves..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'bridge', | |
| label: 'Bridge', | |
| description: 'How to get there', | |
| placeholder: 'e.g., "Using our product..."', | |
| required: true, | |
| }, | |
| ], | |
| }, | |
| STAR: { | |
| id: 'STAR', | |
| name: 'STAR', | |
| description: 'Situation, Task, Action, Result - For case studies', | |
| sections: [ | |
| { | |
| id: 'situation', | |
| label: 'Situation', | |
| description: 'Context', | |
| placeholder: 'e.g., "Company faced declining sales..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'task', | |
| label: 'Task', | |
| description: 'Challenge', | |
| placeholder: 'e.g., "Needed to increase conversion by 20%..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'action', | |
| label: 'Action', | |
| description: 'What happened', | |
| placeholder: 'e.g., "Implemented new email strategy..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'result', | |
| label: 'Result', | |
| description: 'Outcome', | |
| placeholder: 'e.g., "Achieved 35% increase in 3 months..."', | |
| required: true, | |
| }, | |
| ], | |
| }, | |
| PREP: { | |
| id: 'PREP', | |
| name: 'PREP', | |
| description: 'Point, Reason, Example, Point - For persuasive content', | |
| sections: [ | |
| { | |
| id: 'point', | |
| label: 'Point', | |
| description: 'Main argument', | |
| placeholder: 'e.g., "AI will transform healthcare..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'reason', | |
| label: 'Reason', | |
| description: 'Why it matters', | |
| placeholder: 'e.g., "Because it can analyze data faster..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'example', | |
| label: 'Example', | |
| description: 'Proof', | |
| placeholder: 'e.g., "Studies show 90% accuracy in diagnosis..."', | |
| required: true, | |
| }, | |
| { | |
| id: 'pointAgain', | |
| label: 'Point (Restate)', | |
| description: 'Reinforce', | |
| placeholder: 'e.g., "This is why AI is the future of healthcare..."', | |
| required: true, | |
| }, | |
| ], | |
| }, | |
| } | |
| /** | |
| * Generate prompt template from framework and filled sections | |
| */ | |
| export function generateFromFramework( | |
| framework: Framework, | |
| sections: Record<string, string> | |
| ): string { | |
| const parts: string[] = [] | |
| framework.sections.forEach((section) => { | |
| const value = sections[section.id] | |
| if (value) { | |
| parts.push(value) | |
| } | |
| }) | |
| return parts.join('\n\n') | |
| } | |
| /** | |
| * Get framework by ID | |
| */ | |
| export function getFramework(id: string): Framework | undefined { | |
| return FRAMEWORKS[id] | |
| } | |
| /** | |
| * Get all frameworks as array | |
| */ | |
| export function getAllFrameworks(): Framework[] { | |
| return Object.values(FRAMEWORKS) | |
| } | |
| /** | |
| * Detect which framework a prompt might be using | |
| */ | |
| export function detectFramework(template: string): string | null { | |
| // Simple heuristic based on keywords | |
| const lower = template.toLowerCase() | |
| if (lower.includes('you are') && lower.includes('context') && lower.includes('expectation')) { | |
| return 'RACE' | |
| } | |
| if (lower.includes('before') && lower.includes('after')) { | |
| return 'BAB' | |
| } | |
| if (lower.includes('situation') && lower.includes('task') && lower.includes('result')) { | |
| return 'STAR' | |
| } | |
| return null | |
| } | |