Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdavis committed Dec 19, 2024
1 parent 18e5677 commit 34f9b77
Show file tree
Hide file tree
Showing 4 changed files with 443 additions and 278 deletions.
48 changes: 26 additions & 22 deletions apps/registry/app/api/job-similarity/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,37 @@ export async function GET(request) {
console.timeEnd('getJobSimilarityData');

// Parse embeddings and job titles
const parsedData = data.map(item => {
let jobTitle = 'Unknown Position';
let gptContent = null;
try {
gptContent = JSON.parse(item.gpt_content);
jobTitle = gptContent?.title || 'Unknown Position';
} catch (e) {
console.warn('Failed to parse gpt_content for job:', item.uuid);
}
const parsedData = data
.map((item) => {
let jobTitle = 'Unknown Position';
let gptContent = null;
try {
gptContent = JSON.parse(item.gpt_content);
jobTitle = gptContent?.title || 'Unknown Position';
} catch (e) {
console.warn('Failed to parse gpt_content for job:', item.uuid);
}

return {
uuid: item.uuid,
title: jobTitle,
company: gptContent?.company,
countryCode: gptContent?.countryCode,
embedding: typeof item.embedding_v5 === 'string'
? JSON.parse(item.embedding_v5)
: Array.isArray(item.embedding_v5)
? item.embedding_v5
: null
};
}).filter(item => item.embedding !== null);
return {
uuid: item.uuid,
title: jobTitle,
company: gptContent?.company,
countryCode: gptContent?.countryCode,
embedding:
typeof item.embedding_v5 === 'string'
? JSON.parse(item.embedding_v5)
: Array.isArray(item.embedding_v5)
? item.embedding_v5
: null,
};
})
.filter((item) => item.embedding !== null);

return NextResponse.json(parsedData, {
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'public, max-age=86400, s-maxage=86400, stale-while-revalidate=86400',
'Cache-Control':
'public, max-age=86400, s-maxage=86400, stale-while-revalidate=86400',
},
});
} catch (error) {
Expand Down
42 changes: 23 additions & 19 deletions apps/registry/app/api/similarity/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,34 @@ export async function GET(request) {
console.timeEnd('getResumeSimilarityData');

// Parse embeddings from strings to numerical arrays and extract position
const parsedData = data.map(item => {
let resumeData;
try {
resumeData = JSON.parse(item.resume);
} catch (e) {
console.warn('Failed to parse resume for user:', item.username);
resumeData = {};
}
const parsedData = data
.map((item) => {
let resumeData;
try {
resumeData = JSON.parse(item.resume);
} catch (e) {
console.warn('Failed to parse resume for user:', item.username);
resumeData = {};
}

return {
username: item.username,
embedding: typeof item.embedding === 'string'
? JSON.parse(item.embedding)
: Array.isArray(item.embedding)
? item.embedding
: null,
position: resumeData?.basics?.label || 'Unknown Position'
};
}).filter(item => item.embedding !== null);
return {
username: item.username,
embedding:
typeof item.embedding === 'string'
? JSON.parse(item.embedding)
: Array.isArray(item.embedding)
? item.embedding
: null,
position: resumeData?.basics?.label || 'Unknown Position',
};
})
.filter((item) => item.embedding !== null);

return NextResponse.json(parsedData, {
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'public, max-age=86400, s-maxage=86400, stale-while-revalidate=86400',
'Cache-Control':
'public, max-age=86400, s-maxage=86400, stale-while-revalidate=86400',
},
});
} catch (error) {
Expand Down
Loading

0 comments on commit 34f9b77

Please sign in to comment.