Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #52: Added most used language in generating tagline #53

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading