Skip to content

Commit d922b77

Browse files
committed
fix(profile): added review changes
1 parent 7bab3c1 commit d922b77

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

modules/ai_generator.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ def __init__(self):
1212
"""Initialize Groq client"""
1313
self.client = Groq(api_key=Settings.get_groq_key())
1414

15-
def generate_seo_contents(self, profile_data):
15+
def generate_seo_contents(self, profile_data: dict):
1616
"""
1717
Generate a professional SEO-optimized profile content like title, description, keywords
1818
1919
Args:
2020
profile_data (dict): GitHub user profile data
2121
2222
Returns:
23-
str: AI-generated SEO-optimized profile content
23+
dict: AI-generated SEO-optimized profile content
2424
"""
2525
prompt = (
2626
"Generate a concise, professional, and SEO-optimized profile snippet for a developer profile page."
@@ -42,20 +42,39 @@ def generate_seo_contents(self, profile_data):
4242
messages=[
4343
{
4444
"role": "system",
45-
"content": "You are an SEO-optimized profile content generator for developer portfolios and GitHub profiles. Create search engine friendly, professional profile summaries that enhance discoverability and professional presence. Generate content in natural paragraph format without headings, lists, or bullet points. Focus on keyword integration, meta-friendly descriptions, and compelling copy that drives engagement and showcases technical expertise effectively.",
45+
"content": "You are an SEO-optimized profile content generator for developer portfolios and GitHub profiles. Create search engine friendly, professional profile summaries that enhance discoverability and professional presence. Generate content in natural paragraph format without headings, lists, or bullet points. Focus on keyword integration, meta-friendly descriptions, and compelling copy that drives engagement and showcases technical expertise effectively. Your output should be properly formatted JSON when requested, with each field containing well-crafted, SEO-optimized content.",
4646
},
4747
{"role": "user", "content": prompt},
4848
],
4949
model="llama-3.1-8b-instant",
50+
response_format={"type": "json_object"},
5051
)
5152
if not response.choices or response.choices[0].message.content == "":
5253
raise Exception("No response from AI model")
53-
54-
result = json.loads(response.choices[0].message.content)
54+
try:
55+
result = json.loads(response.choices[0].message.content)
56+
except json.JSONDecodeError as e:
57+
raise Exception(f"AI response was not valid JSON. Content: {response.choices[0].message.content}") from e
58+
59+
title = result["title"]
60+
description = result["description"]
61+
keywords = result["keywords"]
62+
63+
if not (title and description and keywords):
64+
missing = []
65+
if not title:
66+
missing.append("title")
67+
if not description:
68+
missing.append("description")
69+
if not keywords:
70+
missing.append("keywords")
71+
raise Exception(
72+
f"AI response missing required SEO fields: {', '.join(missing)}. Received: {result}"
73+
)
5574
return {
56-
"title": result["title"],
57-
"description": result["description"],
58-
"keywords": result["keywords"],
75+
"title": title,
76+
"description": description,
77+
"keywords": keywords,
5978
}
6079

6180
def generate_profile_summary(self, profile_data):

www/app/[username]/layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export async function generateMetadata({
1010
const { username } = await params;
1111
const user = await getProfileData(username);
1212
return {
13-
title: user
13+
title: user?.seo?.title
1414
? user.seo.title
1515
: `Devb.io - Build Stunning Developer Portfolios in Minutes`,
16-
description: user
16+
description: user?.seo?.description
1717
? user.seo.description
1818
: `Passionate developer skilled in modern technologies, building and learning through real-world projects and daily challenges.`,
19-
keywords: user
19+
keywords: user?.seo?.keywords
2020
? user.seo.keywords
2121
: "Developer Portfolio, Devb.io, Software Engineer, Projects, Resume, GitHub Showcase",
2222

0 commit comments

Comments
 (0)