From bc8d21f52114d189b6125f48ee5fd002e3014f50 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 6 Jan 2025 02:17:35 +0300 Subject: [PATCH] duplicate --- .github/workflows/ai_bot.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ai_bot.yml b/.github/workflows/ai_bot.yml index eee38f2..1e3f33d 100644 --- a/.github/workflows/ai_bot.yml +++ b/.github/workflows/ai_bot.yml @@ -135,6 +135,15 @@ jobs: console.log('Analyzing changes to extract prompt information...'); const prompts = new Map(); // Use Map to deduplicate prompts by title + // Helper function to normalize prompt titles + const normalizeTitle = (title) => { + title = title.trim(); + // Remove "Act as" or "Act as a" or "Act as an" from start if present + title = title.replace(/^Act as (?:a |an )?/i, ''); + // Add "Act as" prefix + return `Act as ${title}`; + }; + for (const file of files) { console.log(`Processing file: ${file.filename}`); if (file.filename === 'README.md') { @@ -145,17 +154,17 @@ jobs: .join('\n'); console.log('Attempting to extract prompts from README changes...'); - const promptMatches = [...addedLines.matchAll(/## Act as (?:a |an )?([^\n]+)\n(?:Contributed by:[^\n]*\n)?(?:> )?([^#]+?)(?=\n##|\n\n##|$)/ig)]; + const promptMatches = [...addedLines.matchAll(/## (?:Act as (?:a |an )?)?([^\n]+)\n(?:Contributed by:[^\n]*\n)?(?:> )?([^#]+?)(?=\n##|\n\n##|$)/ig)]; for (const match of promptMatches) { - const actName = `Act as ${match[1].trim()}`; + const actName = normalizeTitle(match[1]); const promptText = match[2].trim(); const contributorLine = addedLines.match(/Contributed by: \[@([^\]]+)\]\(https:\/\/github\.com\/([^\)]+)\)/); const contributorInfo = contributorLine ? `Contributed by: [@${contributorLine[1]}](https://github.com/${contributorLine[2]})` : `Contributed by: [@${pr.user.login}](https://github.com/${pr.user.login})`; - prompts.set(actName, { actName, promptText, contributorInfo }); + prompts.set(actName.toLowerCase(), { actName, promptText, contributorInfo }); console.log(`Found prompt in README: "${actName}"`); } } else if (file.filename === 'prompts.csv') { @@ -170,13 +179,13 @@ jobs: // Parse CSV line considering escaped quotes const matches = [...line.matchAll(/"([^"]*(?:""[^"]*)*)"/g)]; if (matches.length >= 2) { - const actName = matches[0][1].replace(/""/g, '"').trim(); + const actName = normalizeTitle(matches[0][1].replace(/""/g, '"').trim()); const promptText = matches[1][1].replace(/""/g, '"').trim(); // Only add if not already found in README - if (!prompts.has(actName)) { + if (!prompts.has(actName.toLowerCase())) { const contributorInfo = `Contributed by: [@${pr.user.login}](https://github.com/${pr.user.login})`; - prompts.set(actName, { actName, promptText, contributorInfo }); + prompts.set(actName.toLowerCase(), { actName, promptText, contributorInfo }); console.log(`Found prompt in CSV: "${actName}"`); } }