Skip to content

Commit

Permalink
issue 19 resolved. tagline generation using gemini successfully added.
Browse files Browse the repository at this point in the history
  • Loading branch information
garimabhayanaa committed Oct 8, 2024
1 parent 8a7a4f7 commit ad2ddb5
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 5 deletions.
28 changes: 28 additions & 0 deletions ai/generateTagline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { GoogleGenerativeAI } = require("@google/generative-ai");

const genAI = new GoogleGenerativeAI(process.env.GEMINI_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

export async function generateUserTagline(username, contributions) {
const prompt = `
Generate a custom tagline for the GitHub user "${username}" based on the following activity and contribution patterns:
- Total Contributions: ${contributions.totalCommitContributions}
- Active Coding Days: ${contributions.contributionCalendar.totalContributions}
- Most Used Programming Languages: (You can add logic to fetch this info if needed)
The tagline should be consistent, meaningful, and provide an at-a-glance summary of the user's work.
`;

try {
const result = await model.generateContent(prompt);
// Assuming the API returns a JSON object with a 'tagline' field
if (result.response) {
return result.response.text;
} else {
throw new Error("Tagline not found in the response");
}
} catch (error) {
console.error("Error generating tagline:", error);
return "No tagline available"; // Fallback message
}
}
132 changes: 129 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
"lint": "next lint"
},
"dependencies": {
"@google/generative-ai": "^0.21.0",
"axios": "^1.7.7",
"next": "14.2.13",
"next-themes": "^0.3.0",
"react": "^18",
"react": "^18.3.1",
"react-dom": "^18",
"react-hot-toast": "^2.4.1"
},
"devDependencies": {
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.0",
"eslint": "^8",
"eslint-config-next": "14.2.13",
"postcss": "^8",
Expand Down
29 changes: 28 additions & 1 deletion src/app/api/user/route.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextResponse } from "next/server";
import { generateUserTagline } from "../../../../ai/generateTagline";

const GITHUB_API_URL = "https://api.github.com/graphql";

Expand All @@ -13,6 +14,25 @@ export async function POST(req) {
query ($login: String!) {
user(login: $login) {
login
contributionsCollection {
totalCommitContributions
contributionCalendar {
totalContributions
}
pullRequestContributionsByRepository {
repository {
name
}
totalCount
}
}
repositories(first: 100, orderBy: {field: STARGAZERS, direction: DESC}) {
nodes {
primaryLanguage {
name
}
}
}
}
}
`;
Expand Down Expand Up @@ -40,7 +60,14 @@ export async function POST(req) {
const data = await response.json();
console.log(data);
if (data.data.user) {
return NextResponse.json({ exists: true });
const contributions = data.data.user.contributionsCollection;
const tagline = await generateUserTagline(username, contributions);
return NextResponse.json({
exists: true,
totalContributions: contributions.totalCommitContributions,
activeCodingDays: contributions.contributionCalendar.totalContributions,
tagline,
});
} else {
return NextResponse.json({ exists: false });
}
Expand Down

0 comments on commit ad2ddb5

Please sign in to comment.