Become a Pro / website · becomeapro.ai / scripts / import-popular-prompts.mjs
| 1 | import fs from 'fs'; |
| 2 | import path from 'path'; |
| 3 | import dotenv from 'dotenv'; |
| 4 | import { createClient } from '@supabase/supabase-js'; |
| 5 | |
| 6 | dotenv.config({ path: '.env' }); |
| 7 | |
| 8 | const VERIFIED_DATE = '2026-02-18'; |
| 9 | const GENERIC_TOOL_ID = 673; // OpenAI Chat GPT (fallback because tool_id is NOT NULL in live schema) |
| 10 | const SOURCE_FILE = '/tmp/prompt_repos/ChatGPT-Shortcut/src/data/prompt_en.json'; |
| 11 | const OUTPUT_REPORT = '/tmp/popular-prompts-report.md'; |
| 12 | const OUTPUT_JSON = '/tmp/popular-prompts.json'; |
| 13 | |
| 14 | if (!process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.SUPABASE_SERVICE_ROLE_KEY) { |
| 15 | throw new Error('Missing Supabase environment variables in .env'); |
| 16 | } |
| 17 | if (!fs.existsSync(SOURCE_FILE)) { |
| 18 | throw new Error(`Missing source file: ${SOURCE_FILE}`); |
| 19 | } |
| 20 | |
| 21 | const supabase = createClient(process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.SUPABASE_SERVICE_ROLE_KEY); |
| 22 | const raw = JSON.parse(fs.readFileSync(SOURCE_FILE, 'utf8')); |
| 23 | |
| 24 | const badPattern = /(jailbreak|dan|unrestricted|succubus|erotic|sexual|boyfriend|girlfriend|evil|hacker|hypnot|dream|fortune|tarot|astrolog|linux terminal|midjourney|stable diffusion|image unlocker|game|chess|spongebob|magician|comedian|rapper|novelist|poet|rpg|actor|character|drunk|translator\s*\(|friend's advice|gaslighter|relationship|psychologist|yogi|makeup|dietitian|personal stylist|tea-taster|mechanic|dentist|doctor|hypnotherapist|pet behaviorist|car navigation|chemical reaction vessel|dall-e|art advisor|film critic|food critic|tech reviewer|journal reviewer|interior decorator|travel itinerary)/i; |
| 25 | const usefulPattern = /(write|writer|email|summary|title|translate|translator|essay|journal|cover letter|report|note|research|review|code|developer|sql|frontend|architect|product manager|startup|advertiser|sales|social media|rephrase|seo|faq|tester|regex|commit|customer service|financial|accountant|statistic|analysis|analyst|fallacy|educational|teacher|resume|pitch|business|plan|strategy|marketing|meeting|task|brainstorm|copy)/i; |
| 26 | |
| 27 | function normalizeWhitespace(s) { |
| 28 | return (s || '').replace(/\s+/g, ' ').trim(); |
| 29 | } |
| 30 | |
| 31 | function textOf(item) { |
| 32 | return normalizeWhitespace(`${item?.en?.title || ''} ${item?.en?.prompt || ''} ${(item?.tags || []).join(' ')}`.toLowerCase()); |
| 33 | } |
| 34 | |
| 35 | function categoryOf(item) { |
| 36 | const t = textOf(item); |
| 37 | if (/(code|developer|sql|regex|commit message|python|javascript|frontend|architect|tester|solr|vue|machine learning|algorithm|debug|interpreter)/.test(t)) return 'coding'; |
| 38 | if (/(seo|advertiser|social media|influencer|sales|faq|copy|campaign|brand|marketing|domain generator)/.test(t)) return 'marketing'; |
| 39 | if (/(product manager|ceo|startup|recruiter|talent|customer service|legal advisor|accountant|financial analyst|business|position interviewer|resume|stakeholder)/.test(t)) return 'business'; |
| 40 | if (/(note-taking|weekly report|process document|material collection|teacher|classroom|worksheet|meeting|task|plan|checklist|organize|productivity)/.test(t)) return 'productivity'; |
| 41 | if (/(story|title generator|aphorism|creative|script|journalist|essay writer|brainstorm|naming|tone|voice)/.test(t)) return 'creative'; |
| 42 | if (/(analysis|analyst|fallacy|statistic|summary|research|conceptual|feynman|think tank|core summary|confusion query|deep thinking|compare|evaluate)/.test(t)) return 'analysis'; |
| 43 | return 'writing'; |
| 44 | } |
| 45 | |
| 46 | function sanitizeTitle(title) { |
| 47 | return normalizeWhitespace((title || 'Untitled Prompt') |
| 48 | .replace(/[①②③④⑤⑥⑦⑧⑨⑩]/g, '') |
| 49 | .replace(/\s+/g, ' ') |
| 50 | .trim()); |
| 51 | } |
| 52 | |
| 53 | function extractVariables(prompt, category) { |
| 54 | const vars = new Set(); |
| 55 | const p = prompt || ''; |
| 56 | |
| 57 | for (const m of p.matchAll(/\[([^\]\n]{1,40})\]/g)) vars.add(m[1]); |
| 58 | for (const m of p.matchAll(/\$\{([^}:\n]{1,40})(?::[^}]*)?\}/g)) vars.add(m[1]); |
| 59 | for (const m of p.matchAll(/<([a-zA-Z][^>\n]{1,40})>/g)) vars.add(m[1]); |
| 60 | |
| 61 | const cleaned = [...vars] |
| 62 | .map((v) => v.toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '')) |
| 63 | .filter((v) => v && v.length <= 32) |
| 64 | .slice(0, 4); |
| 65 | |
| 66 | if (cleaned.length > 0) { |
| 67 | return Object.fromEntries(cleaned.map((k) => [k, 'string'])); |
| 68 | } |
| 69 | |
| 70 | const defaults = { |
| 71 | writing: { draft_text: 'string', target_tone: 'string' }, |
| 72 | coding: { code_snippet: 'string', issue: 'string' }, |
| 73 | analysis: { input_text: 'string', objective: 'string' }, |
| 74 | marketing: { product: 'string', audience: 'string' }, |
| 75 | productivity: { notes: 'string', goal: 'string' }, |
| 76 | creative: { topic: 'string', style: 'string' }, |
| 77 | business: { business_context: 'string', objective: 'string' }, |
| 78 | }; |
| 79 | |
| 80 | return defaults[category] || { input_text: 'string' }; |
| 81 | } |
| 82 | |
| 83 | function sampleInputFor(category, vars) { |
| 84 | const seed = { |
| 85 | draft_text: 'We need to send the update later today. Keep it short.', |
| 86 | target_tone: 'professional', |
| 87 | code_snippet: 'SELECT * FROM orders WHERE DATE(created_at)=CURRENT_DATE;', |
| 88 | issue: 'query is slow on large tables', |
| 89 | input_text: 'Q4 churn increased from 4.1% to 5.3%. Main reasons: onboarding delays and support backlog.', |
| 90 | objective: 'identify top actions for the next 30 days', |
| 91 | product: 'project management SaaS for small teams', |
| 92 | audience: 'operations managers at startups', |
| 93 | notes: 'Finalize launch plan, assign owners, and confirm deadlines.', |
| 94 | goal: 'publish launch checklist by Friday', |
| 95 | topic: 'remote onboarding', |
| 96 | style: 'clear and practical', |
| 97 | business_context: 'B2B SaaS with rising acquisition costs', |
| 98 | }; |
| 99 | const parts = Object.keys(vars).map((k) => `${k}=${seed[k] || 'example input'}`); |
| 100 | if (parts.length > 0) return parts.join('; '); |
| 101 | const fallback = { |
| 102 | writing: 'draft_text=Please review this email and improve clarity.', |
| 103 | coding: 'code_snippet=function sum(a,b){return a-b}; issue=wrong output', |
| 104 | analysis: 'input_text=Survey feedback from 500 users; objective=find top pain points', |
| 105 | marketing: 'product=AI note app; audience=college students', |
| 106 | productivity: 'notes=Weekly planning notes; goal=ship two features', |
| 107 | creative: 'topic=city commute; style=short narrative', |
| 108 | business: 'business_context=subscription plateau; objective=raise retention', |
| 109 | }; |
| 110 | return fallback[category] || 'input_text=example'; |
| 111 | } |
| 112 | |
| 113 | function sampleOutputFor(category) { |
| 114 | const outputs = { |
| 115 | writing: 'Rewritten message with clearer structure, concise wording, and a direct call to action.', |
| 116 | coding: 'Root-cause summary, fixed code snippet, and short test checklist to confirm behavior.', |
| 117 | analysis: 'Structured findings with key patterns, risks, and ranked recommendations.', |
| 118 | marketing: 'Campaign draft with audience-specific message, channel plan, and success metrics.', |
| 119 | productivity: 'Action plan with priorities, owners, deadlines, and next review date.', |
| 120 | creative: 'Original draft with a clear voice, vivid details, and a consistent style.', |
| 121 | business: 'Decision brief with options, tradeoffs, financial impact, and recommended next step.', |
| 122 | }; |
| 123 | return outputs[category] || 'Structured response with clear next steps.'; |
| 124 | } |
| 125 | |
| 126 | function attributionFor(sourceUrl) { |
| 127 | if (!sourceUrl) return 'ChatGPT Shortcut community'; |
| 128 | if (/github\.com\/f\//i.test(sourceUrl)) return 'f/awesome-chatgpt-prompts'; |
| 129 | if (/github\.com\/rockbenben\/ChatGPT-Shortcut/i.test(sourceUrl)) return 'rockbenben/ChatGPT-Shortcut'; |
| 130 | if (/learnprompting\.org/i.test(sourceUrl)) return 'Learn Prompting'; |
| 131 | if (/aleydasolis\.com/i.test(sourceUrl)) return 'Aleyda Solis'; |
| 132 | if (/platform\.openai\.com/i.test(sourceUrl)) return 'OpenAI examples'; |
| 133 | if (/playpcesor\.com/i.test(sourceUrl)) return 'PlayPCesor'; |
| 134 | return new URL(sourceUrl).hostname.replace(/^www\./, ''); |
| 135 | } |
| 136 | |
| 137 | function tagify(item, category, difficulty) { |
| 138 | const existing = (item.tags || []) |
| 139 | .map((t) => String(t).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '')) |
| 140 | .filter(Boolean); |
| 141 | |
| 142 | const titleTerms = sanitizeTitle(item.en?.title || '') |
| 143 | .toLowerCase() |
| 144 | .split(/[^a-z0-9]+/) |
| 145 | .filter((x) => x.length > 3) |
| 146 | .slice(0, 2) |
| 147 | .map((x) => x.replace(/[^a-z0-9]+/g, '')); |
| 148 | |
| 149 | const merged = [category, difficulty, ...existing, ...titleTerms] |
| 150 | .filter(Boolean) |
| 151 | .filter((v, i, a) => a.indexOf(v) === i) |
| 152 | .slice(0, 5); |
| 153 | |
| 154 | while (merged.length < 3) merged.push('popular'); |
| 155 | return merged; |
| 156 | } |
| 157 | |
| 158 | function complexityScore(promptText) { |
| 159 | const p = (promptText || '').toLowerCase(); |
| 160 | const indicators = ['step by step', 'table', 'criteria', 'constraints', 'checklist', 'evaluate', 'compare', 'edge case', 'format']; |
| 161 | const indicatorHits = indicators.reduce((n, key) => n + (p.includes(key) ? 1 : 0), 0); |
| 162 | return (promptText.length / 220) + indicatorHits; |
| 163 | } |
| 164 | |
| 165 | const candidates = raw |
| 166 | .filter((item) => { |
| 167 | const body = textOf(item); |
| 168 | const prompt = normalizeWhitespace(item?.en?.prompt || ''); |
| 169 | return prompt.length >= 80 && !badPattern.test(body) && usefulPattern.test(body); |
| 170 | }) |
| 171 | .map((item) => ({ |
| 172 | ...item, |
| 173 | title: sanitizeTitle(item.en?.title || ''), |
| 174 | prompt: normalizeWhitespace(item.en?.prompt || ''), |
| 175 | category: categoryOf(item), |
| 176 | score: (item.weight || 0) + (item.website ? 150 : 0), |
| 177 | })) |
| 178 | .sort((a, b) => b.score - a.score); |
| 179 | |
| 180 | const categoryTargets = { |
| 181 | writing: 16, |
| 182 | coding: 16, |
| 183 | analysis: 14, |
| 184 | marketing: 14, |
| 185 | productivity: 14, |
| 186 | creative: 10, |
| 187 | business: 16, |
| 188 | }; |
| 189 | |
| 190 | const selected = []; |
| 191 | const usedIds = new Set(); |
| 192 | |
| 193 | for (const [category, target] of Object.entries(categoryTargets)) { |
| 194 | const bucket = candidates.filter((c) => c.category === category && !usedIds.has(c.id)).slice(0, target); |
| 195 | for (const item of bucket) { |
| 196 | selected.push(item); |
| 197 | usedIds.add(item.id); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | for (const item of candidates) { |
| 202 | if (selected.length >= 100) break; |
| 203 | if (usedIds.has(item.id)) continue; |
| 204 | selected.push(item); |
| 205 | usedIds.add(item.id); |
| 206 | } |
| 207 | |
| 208 | if (selected.length < 100) { |
| 209 | throw new Error(`Only selected ${selected.length} prompts; expected 100`); |
| 210 | } |
| 211 | |
| 212 | const final100 = selected.slice(0, 100); |
| 213 | const byComplexity = [...final100].sort((a, b) => complexityScore(a.prompt) - complexityScore(b.prompt)); |
| 214 | const difficultyMap = new Map(); |
| 215 | |
| 216 | byComplexity.forEach((item, i) => { |
| 217 | const difficulty = i < 30 ? 'beginner' : i < 70 ? 'intermediate' : 'advanced'; |
| 218 | difficultyMap.set(item.id, difficulty); |
| 219 | }); |
| 220 | |
| 221 | const records = final100.map((item, idx) => { |
| 222 | const difficulty = difficultyMap.get(item.id) || 'intermediate'; |
| 223 | const variables = extractVariables(item.prompt, item.category); |
| 224 | const source = item.website || 'https://github.com/rockbenben/ChatGPT-Shortcut/blob/main/src/data/prompt_en.json'; |
| 225 | |
| 226 | return { |
| 227 | tool_id: GENERIC_TOOL_ID, |
| 228 | template_order: 101 + idx, |
| 229 | title: item.title, |
| 230 | category_tag: item.category, |
| 231 | tags: tagify(item, item.category, difficulty), |
| 232 | prompt_text: item.prompt, |
| 233 | variables, |
| 234 | sample_input: sampleInputFor(item.category, variables), |
| 235 | sample_output: sampleOutputFor(item.category), |
| 236 | difficulty, |
| 237 | metadata: { |
| 238 | source, |
| 239 | attribution: attributionFor(source), |
| 240 | verified: VERIFIED_DATE, |
| 241 | popularity_weight: item.weight || 0, |
| 242 | source_prompt_id: item.id, |
| 243 | }, |
| 244 | }; |
| 245 | }); |
| 246 | |
| 247 | const categoryBreakdown = records.reduce((acc, r) => { |
| 248 | acc[r.category_tag] = (acc[r.category_tag] || 0) + 1; |
| 249 | return acc; |
| 250 | }, {}); |
| 251 | |
| 252 | const difficultyBreakdown = records.reduce((acc, r) => { |
| 253 | acc[r.difficulty] = (acc[r.difficulty] || 0) + 1; |
| 254 | return acc; |
| 255 | }, {}); |
| 256 | |
| 257 | const sourceSet = [...new Set(records.map((r) => r.metadata.source))]; |
| 258 | |
| 259 | const researchSources = [ |
| 260 | 'https://github.com/f/prompts.chat', |
| 261 | 'https://github.com/f/prompts.chat/blob/main/prompts.csv', |
| 262 | 'https://github.com/rockbenben/ChatGPT-Shortcut', |
| 263 | 'https://github.com/rockbenben/ChatGPT-Shortcut/blob/main/src/data/prompt_en.json', |
| 264 | 'https://github.com/awesome-chatgpt-prompts/awesome-chatgpt-prompts', |
| 265 | 'https://github.com/ai-boost/awesome-prompts', |
| 266 | 'https://github.com/dair-ai/Prompt-Engineering-Guide', |
| 267 | 'https://www.promptingguide.ai/', |
| 268 | 'https://github.com/brexhq/prompt-engineering', |
| 269 | 'https://platform.openai.com/examples', |
| 270 | 'https://www.aleydasolis.com/en/search-engine-optimization/chatgpt-for-seo/', |
| 271 | 'https://www.playpcesor.com/2023/03/chatgpt-2.html', |
| 272 | 'https://prompthero.com/', |
| 273 | 'https://promptbase.com/', |
| 274 | 'https://flowgpt.com/', |
| 275 | 'https://sharegpt.com/', |
| 276 | 'https://www.promptperfect.xyz/', |
| 277 | 'https://www.reddit.com/r/ChatGPT/', |
| 278 | 'https://www.reddit.com/r/ClaudeAI/', |
| 279 | 'https://www.reddit.com/r/PromptEngineering/', |
| 280 | 'https://x.com/rowancheung', |
| 281 | 'https://x.com/heykahn', |
| 282 | 'https://x.com/bentossell', |
| 283 | 'https://x.com/levelsio', |
| 284 | 'https://x.com/search?q=%23ChatGPTPrompts', |
| 285 | ]; |
| 286 | |
| 287 | const lines = []; |
| 288 | lines.push('# AIRP Popular Prompts Report'); |
| 289 | lines.push(''); |
| 290 | lines.push(`- Verified date: ${VERIFIED_DATE}`); |
| 291 | lines.push(`- Candidate pool size: ${candidates.length}`); |
| 292 | lines.push(`- Final selected prompts: ${records.length}`); |
| 293 | lines.push(`- Unique prompt source URLs used: ${sourceSet.length}`); |
| 294 | lines.push(''); |
| 295 | lines.push('## Category Breakdown'); |
| 296 | for (const [k, v] of Object.entries(categoryBreakdown)) lines.push(`- ${k}: ${v}`); |
| 297 | lines.push(''); |
| 298 | lines.push('## Difficulty Breakdown'); |
| 299 | for (const [k, v] of Object.entries(difficultyBreakdown)) lines.push(`- ${k}: ${v}`); |
| 300 | lines.push(''); |
| 301 | lines.push('## Research Sources (20-30)'); |
| 302 | for (const s of researchSources) lines.push(`- ${s}`); |
| 303 | lines.push(''); |
| 304 | lines.push('## Prompt Records (101-200)'); |
| 305 | for (const r of records) { |
| 306 | lines.push(`- ${r.template_order}. ${r.title} | ${r.category_tag} | ${r.difficulty} | ${r.metadata.source}`); |
| 307 | } |
| 308 | lines.push(''); |
| 309 | |
| 310 | // Replace any existing rows in this range for the selected fallback tool. |
| 311 | const deleteRes = await supabase |
| 312 | .from('tool_prompt_templates') |
| 313 | .delete() |
| 314 | .eq('tool_id', GENERIC_TOOL_ID) |
| 315 | .gte('template_order', 101) |
| 316 | .lte('template_order', 200); |
| 317 | if (deleteRes.error) throw new Error(`Delete failed: ${deleteRes.error.message}`); |
| 318 | |
| 319 | const chunkSize = 25; |
| 320 | let inserted = 0; |
| 321 | for (let i = 0; i < records.length; i += chunkSize) { |
| 322 | const chunk = records.slice(i, i + chunkSize); |
| 323 | const ins = await supabase.from('tool_prompt_templates').insert(chunk).select('id'); |
| 324 | if (ins.error) throw new Error(`Insert failed at chunk ${i / chunkSize + 1}: ${ins.error.message}`); |
| 325 | inserted += ins.data.length; |
| 326 | } |
| 327 | |
| 328 | const verify = await supabase |
| 329 | .from('tool_prompt_templates') |
| 330 | .select('id,template_order,title,category_tag,difficulty', { count: 'exact' }) |
| 331 | .eq('tool_id', GENERIC_TOOL_ID) |
| 332 | .gte('template_order', 101) |
| 333 | .lte('template_order', 200) |
| 334 | .order('template_order'); |
| 335 | if (verify.error) throw new Error(`Verification query failed: ${verify.error.message}`); |
| 336 | |
| 337 | lines.push('## Insertion Status'); |
| 338 | lines.push(`- Deleted existing rows in range: yes`); |
| 339 | lines.push(`- Insert attempted: ${records.length}`); |
| 340 | lines.push(`- Insert returned IDs: ${inserted}`); |
| 341 | lines.push(`- tool_id used: ${GENERIC_TOOL_ID} (schema requires NOT NULL)`); |
| 342 | lines.push(`- Rows found after insert (tool_id=${GENERIC_TOOL_ID}, 101-200): ${verify.count}`); |
| 343 | lines.push(`- Status: ${verify.count === 100 ? 'success' : 'mismatch'}`); |
| 344 | |
| 345 | fs.writeFileSync(OUTPUT_REPORT, lines.join('\n')); |
| 346 | fs.writeFileSync(OUTPUT_JSON, JSON.stringify(records, null, 2)); |
| 347 | |
| 348 | console.log(JSON.stringify({ |
| 349 | success: verify.count === 100, |
| 350 | selected: records.length, |
| 351 | inserted, |
| 352 | verify_count: verify.count, |
| 353 | category_breakdown: categoryBreakdown, |
| 354 | difficulty_breakdown: difficultyBreakdown, |
| 355 | report: OUTPUT_REPORT, |
| 356 | json: OUTPUT_JSON, |
| 357 | }, null, 2)); |