Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
Add openai integration for job/resume matching
Khuram Niaz0081995aa7c5
diff --git a/src/actions/ai.actions.ts b/src/actions/ai.actions.tsindex ecf68e0..1723120 100644--- a/src/actions/ai.actions.ts+++ b/src/actions/ai.actions.ts@@ -119,11 +119,11 @@ export const getResumeReviewByOpenAi = async (});};-export const getJobMatchByAi = async (+export const getJobMatchByOllama = async (resume: Resume,job: JobResponse,- modelProvider?: string-): Promise<any | undefined> => {+ aiModel?: string+): Promise<ReadableStream | undefined> => {const resumeText = await convertResumeToText(resume);const jobText = await convertJobToText(job);@@ -136,7 +136,6 @@ export const getJobMatchByAi = async (Your response must always return JSON object with following structure:- "matching_score": <matching_score with single numeric value, be strict with this score with always room for improvement>,"detailed_analysis": an array list of following object structures:<<object structure>>"category": "suggestion category title with score",@@ -163,6 +162,7 @@ export const getJobMatchByAi = async ("additional_comments": summary of recommendations as array of strings.<<example>>["<comments>"],+ "matching_score": <matching_score with single numeric value, be strict with this score with always room for improvement>,`,],[@@ -189,7 +189,7 @@ export const getJobMatchByAi = async (});const model = new ChatOllama({baseUrl: process.env.OLLAMA_BASE_URL || "http://127.0.0.1:11434",- model: "llama3.1",+ model: aiModel,temperature: 0,format: "json",maxConcurrency: 1,@@ -210,3 +210,94 @@ export const getJobMatchByAi = async (},});};++export const getJobMatchByOpenAi = async (+ resume: Resume,+ job: JobResponse,+ aiModel?: string+): Promise<ReadableStream | undefined> => {+ const resumeText = await convertResumeToText(resume);++ const jobText = await convertJobToText(job);++ const prompt = ChatPromptTemplate.fromMessages([+ [+ "system",+ `+ You are an expert assistant tasked with matching job seekers' resumes with job descriptions and providing suggestions to improve their resumes. You will analyze the given resume and job description, provide a matching score between 0 and 100, score will be based on application tracking system (ATS) friendliness and skill and keywords match, and suggest improvements to increase the matching score and make the resume more aligned with the job description. Be verbose and highlight details in your response.++ Your response must always return JSON object with following structure:++ "detailed_analysis": an array list of following object structures:+ <<object structure>>+ "category": "suggestion category title with score",+ "value": "an array list of suggestion as strings",+ <<example 1>>+ "category": "ATS Friendliness(60/100):",+ "value": ["<ATS friendliness analysis 1>", "<ATS friendliness analysis 2>",...],+ <<example 2>>+ "category": "Skill and Keyword match(65/100):",+ "value": ["<description of analysis in terms of skill match>", "<description of analysis in terms of keyword match>",...],+ "suggestions": an array list with following object structures:+ <<object structure>>+ "category": "suggestion category title",+ "value": "an array list of suggestion as strings",+ <<example 1>>+ "category": "Emphasize Keywords and Skills:",+ "value": ["<missing keywords not found in resume>", "<missing skill not found in resume>",...],+ <<example 2>>+ "category": "Format for clarity and ATS optimization:",+ "value": ["<change 1>", "<change 2>",...],+ <<example 3>>+ "category": "Enhancement for relevant experience:",+ "value": ["<change 1>", "<change 2>",...],+ "additional_comments": summary of recommendations as array of strings.+ <<example>>+ ["<comments>"],+ "matching_score": <matching_score with single numeric value, be strict with this score with always room for improvement>,+ `,+ ],+ [+ "human",+ `+ Please analyze the following resume and job description.++ Resume:+ """+ {resume}+ """++ Job Description:+ """+ {job_description}+ """+ `,+ ],+ ]);++ const inputMessage = await prompt.format({+ resume: resumeText || "No resume provided",+ job_description: jobText,+ });+ const model = new ChatOpenAI({+ model: aiModel,+ openAIApiKey: process.env.OPENAI_API_KEY,+ temperature: 0,+ maxConcurrency: 1,+ maxTokens: 3000,+ });++ const stream = await model+ .pipe(new StringOutputParser())+ .stream(inputMessage);+ const encoder = new TextEncoder();++ return new ReadableStream({+ async start(controller) {+ for await (const chunk of stream) {+ controller.enqueue(encoder.encode(chunk));+ }+ controller.close();+ },+ });+};diff --git a/src/app/api/ai/resume/match/route.ts b/src/app/api/ai/resume/match/route.tsindex bd432de..7f15f3e 100644--- a/src/app/api/ai/resume/match/route.ts+++ b/src/app/api/ai/resume/match/route.ts@@ -4,9 +4,11 @@ import { auth } from "@/auth";import { NextApiRequest, NextApiResponse } from "next";import { NextRequest, NextResponse } from "next/server";import { Resume } from "@/models/profile.model";-import { getJobMatchByAi } from "@/actions/ai.actions";+import { getJobMatchByOllama, getJobMatchByOpenAi } from "@/actions/ai.actions";import { getResumeById } from "@/actions/profile.actions";import { getJobDetails } from "@/actions/job.actions";+import { AiModel, AiProvider } from "@/models/ai.model";+import { JobResponse } from "@/models/job.model";export const POST = async (req: NextRequest, res: NextApiResponse) => {const session = await auth();@@ -15,18 +17,29 @@ export const POST = async (req: NextRequest, res: NextApiResponse) => {if (!session || !session.user) {return res.status(401).json({ message: "Not Authenticated" });}+ const { resumeId, jobId, selectedModel } = (await req.json()) as {+ resumeId: string;+ jobId: string;+ selectedModel: AiModel;+ };try {- if (!req.body) {- throw new Error("Resume and Job Id is required");+ if (!resumeId || !jobId || !selectedModel) {+ throw new Error("ResumeId, Job Id and selectedModel is required");}- const { resumeId, jobId } = await req.json();- const [resume, { job }] = await Promise.all([- getResumeById(resumeId),- getJobDetails(jobId),- ]);+ const [resume, { job }]: [Resume, { job: JobResponse }] = await Promise.all(+ [getResumeById(resumeId), getJobDetails(jobId)]+ );- const response = await getJobMatchByAi(resume, job);+ let response;+ switch (selectedModel.provider) {+ case AiProvider.OPENAI:+ response = await getJobMatchByOpenAi(resume, job, selectedModel.model);+ break;+ default:+ response = await getJobMatchByOllama(resume, job, selectedModel.model);+ break;+ }return new NextResponse(response, {headers: {diff --git a/src/components/profile/AiJobMatchResponseContent.tsx b/src/components/profile/AiJobMatchResponseContent.tsxindex 786b966..bf40b3f 100644--- a/src/components/profile/AiJobMatchResponseContent.tsx+++ b/src/components/profile/AiJobMatchResponseContent.tsx@@ -1,75 +1,84 @@import { RadialChartComponent } from "../RadialChart";+import { RadialChartSekeleton } from "../RadialChartSekeleton";import { SheetDescription } from "../ui/sheet";import { parse } from "best-effort-json-parser";-export const AiJobMatchResponseContent = ({ content }: { content: any }) => {+interface Analysis {+ category: string;+ value: string[];+}++interface ParsedContent {+ matching_score: number;+ detailed_analysis: Analysis[];+ suggestions: Analysis[];+ additional_comments: string[];+}++export const AiJobMatchResponseContent = ({ content }: { content: string }) => {+ if (content.length <= 1) return null;+ const parsedContent: ParsedContent = parse(content);return (<>- {content.length > 1 && (- <>- <div className="pt-2">- {parse(content).matching_score && (- <RadialChartComponent score={parse(content).matching_score} />- )}- </div>- <div className="mt-[-50px]">- {parse(content).detailed_analysis && (- <>- <h2 className="font-semibold mb-2">Detailed Analysis:</h2>- {parse(content).detailed_analysis.map(- (analysis: any, i: number) => (- <div key={i}>- <h2 className="font-medium my-1">- {analysis.toString().length > 1 && analysis.category}- </h2>- <SheetDescription>- {analysis.value &&- analysis.value.map((v: string, j: number) => {- return <li key={j}>{v}</li>;- })}- </SheetDescription>- </div>- )- )}- </>- )}- </div>- <div className="pt-2">- {parse(content).suggestions && (- <>- <h2 className="font-semibold mb-2">Suggestions: </h2>- {parse(content).suggestions.map((analysis: any, i: number) => (- <div key={i}>- <h2 className="font-medium my-1">- {analysis.toString().length > 1 && analysis.category}- </h2>- <SheetDescription>- {analysis.value &&- analysis.value.map((v: string, j: number) => {- return <li key={j}>{v}</li>;- })}- </SheetDescription>- </div>- ))}- </>- )}- </div>- <div className="pt-2">- {parse(content).additional_comments && (- <>- <h2 className="font-semibold mb-2">Additional Comments: </h2>+ <div className="pt-2 flex justify-center">+ {parsedContent.matching_score ? (+ <RadialChartComponent score={parsedContent.matching_score} />+ ) : (+ <RadialChartSekeleton />+ )}+ </div>+ <div className="mt-[-50px]">+ {parsedContent.detailed_analysis && (+ <>+ <h2 className="font-semibold mb-2">Detailed Analysis:</h2>+ {parsedContent.detailed_analysis.map((analysis: any, i: number) => (+ <div key={i}>+ <h2 className="font-medium my-1">+ {analysis.toString().length > 1 && analysis.category}+ </h2>+ <SheetDescription>+ {analysis.value &&+ analysis.value.map((v: string, j: number) => {+ return <li key={j}>{v}</li>;+ })}+ </SheetDescription>+ </div>+ ))}+ </>+ )}+ </div>+ <div className="pt-2">+ {parsedContent.suggestions && (+ <>+ <h2 className="font-semibold mb-2">Suggestions: </h2>+ {parsedContent.suggestions.map((analysis: any, i: number) => (+ <div key={i}>+ <h2 className="font-medium my-1">+ {analysis.toString().length > 1 && analysis.category}+ </h2><SheetDescription>- {parse(content).additional_comments.map(- (c: string, i: number) => {- return <li key={i}>{c}</li>;- }- )}+ {analysis.value &&+ analysis.value.map((v: string, j: number) => {+ return <li key={j}>{v}</li>;+ })}</SheetDescription>- </>- )}- </div>- </>- )}+ </div>+ ))}+ </>+ )}+ </div>+ <div className="pt-2">+ {parsedContent.additional_comments && (+ <>+ <h2 className="font-semibold mb-2">Additional Comments: </h2>+ <SheetDescription>+ {parsedContent.additional_comments.map((c: string, i: number) => {+ return <li key={i}>{c}</li>;+ })}+ </SheetDescription>+ </>+ )}+ </div></>);};diff --git a/src/components/profile/AiJobMatchSection.tsx b/src/components/profile/AiJobMatchSection.tsxindex ba8eca7..7339dde 100644--- a/src/components/profile/AiJobMatchSection.tsx+++ b/src/components/profile/AiJobMatchSection.tsx@@ -93,7 +93,7 @@ export const AiJobMatchSection = ({const response = await fetch("/api/ai/resume/match", {method: "POST",headers: { "Content-Type": "application/json" },- body: JSON.stringify({ resumeId, jobId }),+ body: JSON.stringify({ resumeId, jobId, selectedModel }),signal: abortController.signal,});