Skip to content

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.

add openai model integration for resume review

Khuram Niaz88a989c8e2e6
diff --git a/src/actions/ai.actions.ts b/src/actions/ai.actions.ts
index 6cd73ec..ecf68e0 100644
--- a/src/actions/ai.actions.ts
+++ b/src/actions/ai.actions.ts
@@ -1,40 +1,29 @@
"use server";
import { ChatOpenAI } from "@langchain/openai";
-import { HumanMessage, SystemMessage } from "@langchain/core/messages";
import { ChatOllama } from "@langchain/community/chat_models/ollama";
-import { StringOutputParser } from "@langchain/core/output_parsers";
+import {
+ StringOutputParser,
+ StructuredOutputParser,
+} from "@langchain/core/output_parsers";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { Resume } from "@/models/profile.model";
import { JobResponse } from "@/models/job.model";
import { convertJobToText, convertResumeToText } from "@/utils/ai.utils";
-export const getResumeReviewByAi = async (
+export const getResumeReviewByOllama = async (
resume: Resume,
aImodel?: string
-): Promise<any | undefined> => {
- // const model2 = new ChatOpenAI({
- // modelName: "gpt-3.5-turbo",
- // openAIApiKey: process.env.OPENAI_API_KEY,
- // });
-
- // const messages = [
- // new SystemMessage("Translate the following from English into Italian"),
- // new HumanMessage("hi!"),
- // ];
- // const prompt1 = ChatPromptTemplate.fromMessages(messages);
- // const output1 = await model2.invoke(messages);
- // console.log({ output1 });
-
+): Promise<ReadableStream | undefined> => {
const prompt = ChatPromptTemplate.fromMessages([
[
"system",
`
- You are an expert resume writer. You must always return JSON object with following structure.
+ You are an expert resume writer and career coach. You must always return JSON object with following structure.
- summary: Provide a brief summary of the resume.
- strengths: List the strengths of the resume.
- weaknesses: List the weaknesses of the resume.
+ summary: Provide a brief summary of the resume review.
+ strengths: List the strengths in the resume.
+ weaknesses: List the weaknesses in the resume.
suggestions: Provide suggestions for improvement in a list of string.
score: Provide a score for the resume (0-100).
`,
@@ -62,9 +51,62 @@ export const getResumeReviewByAi = async (
const stream = await model
.pipe(new StringOutputParser())
- // .invoke(inputMessage);
.stream(inputMessage);
- // return response;
+ const encoder = new TextEncoder();
+
+ return new ReadableStream({
+ async start(controller) {
+ for await (const chunk of stream) {
+ controller.enqueue(encoder.encode(chunk));
+ }
+ controller.close();
+ },
+ });
+};
+
+export const getResumeReviewByOpenAi = async (
+ resume: Resume,
+ aImodel?: string
+): Promise<ReadableStream | undefined> => {
+ const prompt = ChatPromptTemplate.fromMessages([
+ [
+ "system",
+ `
+ You are an expert resume writer and career coach. You must only return JSON object with following property structure.
+
+ summary: Provide a brief summary of the resume review.
+ strengths: List the strengths in the resume.
+ weaknesses: List the weaknesses in the resume.
+ suggestions: Provide suggestions for improvement in a list of string.
+ score: Provide a score for the resume (0-100), scoring should be strict and criteria should include skills, ATS friendliness, and formatting.
+ `,
+ ],
+ [
+ "human",
+ `
+ Review the resume provided below and and provide feedback in the specified JSON format.
+
+ {resume}
+ `,
+ ],
+ ]);
+
+ const resumeText = await convertResumeToText(resume);
+
+ const inputMessage = await prompt.format({ resume: resumeText });
+
+ const model = new ChatOpenAI({
+ modelName: 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({
diff --git a/src/app/api/ai/resume/review/route.ts b/src/app/api/ai/resume/review/route.ts
index c25434f..4d71791 100644
--- a/src/app/api/ai/resume/review/route.ts
+++ b/src/app/api/ai/resume/review/route.ts
@@ -2,10 +2,13 @@ import "server-only";
import { auth } from "@/auth";
import { NextApiRequest, NextApiResponse } from "next";
-import { getResumeReviewByAi } from "@/actions/ai.actions";
+import {
+ getResumeReviewByOllama,
+ getResumeReviewByOpenAi,
+} from "@/actions/ai.actions";
import { NextRequest, NextResponse } from "next/server";
import { Resume } from "@/models/profile.model";
-import { AiModel } from "@/models/ai.model";
+import { AiModel, AiProvider } from "@/models/ai.model";
export const POST = async (req: NextRequest, res: NextApiResponse) => {
const session = await auth();
@@ -22,7 +25,16 @@ export const POST = async (req: NextRequest, res: NextApiResponse) => {
if (!resume || !selectedModel) {
throw new Error("Resume or selected model is required");
}
- const response = await getResumeReviewByAi(resume, selectedModel.model);
+
+ let response;
+ switch (selectedModel.provider) {
+ case AiProvider.OPENAI:
+ response = await getResumeReviewByOpenAi(resume, selectedModel.model);
+ break;
+ default:
+ response = await getResumeReviewByOllama(resume, selectedModel.model);
+ break;
+ }
return new NextResponse(response, {
headers: {
diff --git a/src/app/dashboard/settings/page.tsx b/src/app/dashboard/settings/page.tsx
index 358ba47..91c55dc 100644
--- a/src/app/dashboard/settings/page.tsx
+++ b/src/app/dashboard/settings/page.tsx
@@ -9,10 +9,10 @@ function Settings() {
<h3 className="text-2xl font-semibold leading-none tracking-tight mb-4">
Settings
</h3>
- <Tabs defaultValue="display">
+ <Tabs defaultValue="ai">
<TabsList>
- <TabsTrigger value="display">Display</TabsTrigger>
<TabsTrigger value="ai">AI</TabsTrigger>
+ <TabsTrigger value="display">Display</TabsTrigger>
</TabsList>
<TabsContent value="display">
<DisplaySettings />
diff --git a/src/components/profile/AiResumeReviewResponseContent.tsx b/src/components/profile/AiResumeReviewResponseContent.tsx
index 76450bd..d749f1b 100644
--- a/src/components/profile/AiResumeReviewResponseContent.tsx
+++ b/src/components/profile/AiResumeReviewResponseContent.tsx
@@ -39,6 +39,9 @@ export const AiResumeReviewResponseContent = ({
{weaknesses && <Section title="Weaknesses" items={weaknesses} />}
{suggestions && <Section title="Suggestions" items={suggestions} />}
</div>
+ {/* <pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">
+ <code className="text-white">{parse(content)}</code>
+ </pre> */}
</>
);
};
diff --git a/src/models/ai.model.ts b/src/models/ai.model.ts
index d5867b0..ebf3f93 100644
--- a/src/models/ai.model.ts
+++ b/src/models/ai.model.ts
@@ -33,6 +33,8 @@ export enum OllamaModel {
export enum OpenaiModel {
GPT3_5 = "gpt-3.5-turbo",
+ // GPT4o = "gpt-4o",
+ // GPT4_TURBO = "gpt-4-turbo", // expensive model, but faster
}
export const defaultModel: AiModel = {