From 4770a602599d97f9440709ccbb70285eca28981e Mon Sep 17 00:00:00 2001 From: nithinrvs Date: Sat, 26 Oct 2024 22:01:04 +0530 Subject: [PATCH] issue #52: Added most used language in generating tagline --- ai/generateTagline.js | 5 +++-- src/app/api/ai/route.js | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ai/generateTagline.js b/ai/generateTagline.js index b825b83..7976746 100644 --- a/ai/generateTagline.js +++ b/ai/generateTagline.js @@ -3,11 +3,12 @@ const { GoogleGenerativeAI } = require("@google/generative-ai"); const genAI = new GoogleGenerativeAI(process.env.API); const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" }); -export async function generateUserTagline(username, contributions) { +export async function generateUserTagline(username, contributions, mostUsedLanguage) { const prompt = ` - Generate a custom tagline for the GitHub user "${username}" based on the following activity and contribution patterns: + Generate a custom tagline for the GitHub user "${username}" based on the following activity, contribution patterns and most used language: - Total Contributions: ${contributions.totalCommitContributions} - Active Coding Days: ${contributions.contributionCalendar.totalContributions} + - most used language: ${mostUsedLanguage} The tagline should be consistent, meaningful, and provide an at-a-glance summary of the user's work.. Only generate one tagline, only one. diff --git a/src/app/api/ai/route.js b/src/app/api/ai/route.js index 873f17d..651667e 100644 --- a/src/app/api/ai/route.js +++ b/src/app/api/ai/route.js @@ -64,9 +64,25 @@ export async function POST(req) { const data = await response.json(); // console.log(data); if (data.data.user) { + const repositories = data.data.user.repositories.nodes; + + // Count each language's occurrence + const languageCounts = {}; + repositories.forEach(repo => { + const language = repo.primaryLanguage?.name; + if (language) { + languageCounts[language] = (languageCounts[language] || 0) + 1; + } + }); + + // Determine the most used language(s) + const mostUsedLanguages = Object.keys(languageCounts).sort( + (a, b) => languageCounts[b] - languageCounts[a] + ); + const contributions = data.data.user.contributionsCollection; // console.log(contributions) - const tagline = await generateUserTagline(username, contributions); + const tagline = await generateUserTagline(username, contributions, mostUsedLanguages.slice(0, 1)); return NextResponse.json({ exists: true, tagline,