Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 20 additions & 8 deletions netlify/functions/enhanceWithAi.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GoogleGenerativeAI } from '@google/generative-ai';
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';

const enhanceWithAi = async ({
apiKey,
professionalSummary,
Expand All @@ -12,9 +13,10 @@ const enhanceWithAi = async ({
if (!apiKey) {
throw new Error('API key is required');
}
const genAI = new GoogleGenerativeAI(apiKey);
const model = genAI.getGenerativeModel({ model: 'gemini-1.5-flash' });

const genAI = new ChatGoogleGenerativeAI({
apiKey,
model: 'gemini-1.5-flash',
});
const systemPrompt = `You are an expert AI resume writer specializing in creating ATS-optimized, recruiter-friendly CVs for tech professionals with career transitions and non-traditional backgrounds.

**Your Task:** Enhance the provided CV data by optimizing it for:
Expand Down Expand Up @@ -99,11 +101,21 @@ const enhanceWithAi = async ({

Only return valid JSON without any additional formatting or commentary.`;

const result = await model.generateContent({
contents: [{ role: 'user', parts: [{ text: systemPrompt }] }],
});
const result = await genAI.invoke([
{ role: 'user', content: systemPrompt },
]);

const responseText =
typeof result?.content === 'string'
? result.content
: typeof result?.text === 'string'
? result.text
: Array.isArray(result?.content)
? result.content
.map((cont: any) => (typeof cont === 'string' ? cont : cont.text || ''))
.join('\n')
: '';

const responseText = result.response.text();
const cleanedResponse = responseText
.replace(/```json\n?/g, '')
.replace(/```\n?/g, '')
Expand Down
Loading