Skip to content

Commit

Permalink
issue #52: Added most used language in generating tagline
Browse files Browse the repository at this point in the history
  • Loading branch information
nithinrvs committed Oct 26, 2024
1 parent 0b27bd3 commit 4770a60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ai/generateTagline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 17 additions & 1 deletion src/app/api/ai/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4770a60

Please sign in to comment.