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
Stream resume review response
Khuram Niazb677c79e0b81
diff --git a/src/actions/ai.actions.ts b/src/actions/ai.actions.tsindex f593196..2a1e3dd 100644--- a/src/actions/ai.actions.ts+++ b/src/actions/ai.actions.ts@@ -5,8 +5,17 @@ import { HumanMessage, SystemMessage } from "@langchain/core/messages";import { ChatOllama } from "@langchain/community/chat_models/ollama";import { StringOutputParser } from "@langchain/core/output_parsers";import { ChatPromptTemplate } from "@langchain/core/prompts";+import {+ ContactInfo,+ Education,+ Resume,+ ResumeSection,+ SectionType,+ WorkExperience,+} from "@/models/profile.model";export const getResumeReviewByAi = async (+ resume: Resume,modelProvider?: string): Promise<any | undefined> => {// const model = new ChatOpenAI({@@ -19,26 +28,36 @@ export const getResumeReviewByAi = async (// new HumanMessage("hi!"),// ];- // const prompt = ChatPromptTemplate.fromMessages([- // [- // "system",- // `You are an expert resume writer. Format all responses as JSON objects.`,- // ],- // ["human", `Translate "{input}" into {language}.`],- // ]);+ const prompt = ChatPromptTemplate.fromMessages([+ [+ "system",+ `+ You are an expert resume writer. Format all responses as JSON object in the following format.++ summary: Provide a brief summary of the resume.+ strengths: List the strengths of the resume.+ weaknesses: List the weaknesses of the resume.+ suggestions: Provide suggestions for improvement in a list.+ score: Provide a score for the resume (0-100).+ `,+ ],+ ["human", `Review the resume {resume} and provide feedback.`],+ ]);+ const resumeText = convertResumeToText(resume);++ const inputMessage = await prompt.format({ resume: resumeText });const model = new ChatOllama({baseUrl: process.env.OLLAMA_BASE_URL || "http://localhost:11434",model: "llama3",- // format: "json",+ format: "json",});const stream = await model.pipe(new StringOutputParser())- .stream(- `Write a resume summary of 100 words at most for a software engineer, focusing on experience with Python and JavaScript.`- );-+ // .invoke(inputMessage);+ .stream(inputMessage);+ // return response;const encoder = new TextEncoder();return new ReadableStream({@@ -50,3 +69,86 @@ export const getResumeReviewByAi = async (},});};++const convertResumeToText = (resume: Resume) => {+ const formatContactInfo = (contactInfo?: ContactInfo) => {+ if (!contactInfo) return "";+ return `+ Name: ${contactInfo.firstName} ${contactInfo.lastName}+ Headline: ${contactInfo.headline}+ Email: ${contactInfo.email || "N/A"}+ Phone: ${contactInfo.phone || "N/A"}+ Address: ${contactInfo.address || "N/A"}+ `;+ };++ const formatWorkExperiences = (workExperiences?: WorkExperience[]) => {+ if (!workExperiences || workExperiences.length === 0) return "";+ return workExperiences+ .map(+ (experience) => `+ Company: ${experience.Company.label}+ Job Title: ${experience.jobTitle.label}+ Location: ${experience.location.label}+ Description: ${experience.description}+ `+ )+ .join("\n");+ };+ // Start Date: ${experience.startDate.toLocaleDateString().split("T")[0]}+ // End Date: ${+ // experience.currentJob+ // ? "Present"+ // : experience.endDate.toLocaleDateString().split("T")[0]+ // }++ const formatEducation = (educations?: Education[]) => {+ if (!educations || educations.length === 0) return "";+ return (+ educations+ .map(+ (education) => `+ Institution: ${education.institution}+ Degree: ${education.degree}+ Field of Study: ${education.fieldOfStudy}+ Location: ${education.location}+ Description: ${education.description || "N/A"}+ `+ )+ // Start Date: ${education.startDate.toLocaleDateString().split("T")[0]}+ // End Date: ${+ // education.endDate+ // ? education.endDate.toLocaleDateString().split("T")[0]+ // : "N/A"+ // }+ .join("\n")+ );+ };++ const formatResumeSections = (sections?: ResumeSection[]) => {+ if (!sections || sections.length === 0) return "";+ return sections+ .map((section) => {+ switch (section.sectionType) {+ case SectionType.SUMMARY:+ return `Summary: ${section.summary?.content || "N/A"}`;+ case SectionType.EXPERIENCE:+ return formatWorkExperiences(section.workExperiences);+ case SectionType.EDUCATION:+ return formatEducation(section.educations);+ default:+ return "";+ }+ })+ .join("\n");+ };++ const inputMessage = `+ You are an expert resume reviewer, review the following resume:++ Title: ${resume.title}+ ${formatContactInfo(resume.ContactInfo)}+ ${formatResumeSections(resume.ResumeSections)}+ `;+ return inputMessage;+};diff --git a/src/app/api/ai/route.ts b/src/app/api/ai/route.tsindex d386f99..dedcab3 100644--- a/src/app/api/ai/route.ts+++ b/src/app/api/ai/route.ts@@ -3,12 +3,13 @@ import "server-only";import { auth } from "@/auth";import { NextApiRequest, NextApiResponse } from "next";import { getResumeReviewByAi } from "@/actions/ai.actions";-import { NextResponse } from "next/server";+import { NextRequest, NextResponse } from "next/server";import { ChatOllama } from "@langchain/community/chat_models/ollama";import { StringOutputParser } from "@langchain/core/output_parsers";import { ChatPromptTemplate } from "@langchain/core/prompts";+import { Resume } from "@/models/profile.model";-export const GET = async (req: NextApiRequest, res: NextApiResponse) => {+export const POST = async (req: NextRequest, res: NextApiResponse) => {const session = await auth();console.log("SESSION USER: ", session?.user);const userId = session?.accessToken.sub;@@ -16,16 +17,15 @@ export const GET = async (req: NextApiRequest, res: NextApiResponse) => {if (!session || !session.user) {return res.status(401).json({ message: "Not Authenticated" });}-- // const { label, value } = await req.body();- // if (!value) {- // return res.status(400).json({ message: "Input text is required" });- // }-try {- const readableStream = await getResumeReviewByAi();+ if (!req.body) {+ throw new Error("Resume is required");+ }+ const resume = (await req.json()) as Resume;++ const response = await getResumeReviewByAi(resume);- return new NextResponse(readableStream, {+ return new NextResponse(response, {headers: {"Content-Type": "text/event-stream","Cache-Control": "no-cache",@@ -38,7 +38,7 @@ export const GET = async (req: NextApiRequest, res: NextApiResponse) => {if (error instanceof Error) {if (error.message === "fetch failed") {error.message =- "Fetch failed, please make sure selected AI service is running.";+ "Fetch failed, please make sure selected AI provider service is running.";}return NextResponse.json({ error: error.message },diff --git a/src/components/AiSection.tsx b/src/components/AiSection.tsxindex 5d47ce4..5f9b4cb 100644--- a/src/components/AiSection.tsx+++ b/src/components/AiSection.tsx@@ -11,44 +11,42 @@ import {SheetTitle,} from "./ui/sheet";import Loading from "./Loading";-import { useCallback, useEffect, useState } from "react";+import { useCallback, useEffect, useRef, useState } from "react";import { toast } from "./ui/use-toast";+import { Resume } from "@/models/profile.model";+import { ResumeReviewResponse } from "@/models/ai.model";+import { Editor, EditorContent } from "@tiptap/react";+import StarterKit from "@tiptap/starter-kit";interface AiSectionProps {- getAiResponse: () => void;+ resume: Resume;}-const AiSection = () => {- const [aIContent, setAIContent] = useState("");+const AiSection = ({ resume }: AiSectionProps) => {+ const [aIContent, setAIContent] = useState<ResumeReviewResponse | any>({+ summary: "",+ strengths: [],+ weaknesses: [],+ suggestions: [],+ score: 0,+ });const [aISectionOpen, setAiSectionOpen] = useState(false);const [loading, setLoading] = useState(false);let reader: ReadableStreamDefaultReader<Uint8Array> | null = null;- let isStreaming = true;- const terminateStream = useCallback(() => {- if (reader) {- console.log("Stream terminated");- isStreaming = false;- reader- .cancel()- .catch((error) => console.error("Stream cancel error:", error));- }- }, [reader]);- useEffect(() => {- if (!aISectionOpen) {- setAIContent("");- terminateStream();- }- }, [aISectionOpen, terminateStream]);++ useEffect(() => {}, []);const getResumeReview = async () => {try {+ if (!resume || resume.ResumeSections?.length === 0) {+ throw new Error("Resume content is required");+ }setAiSectionOpen(true);setLoading(true);-const response = await fetch("/api/ai", {- method: "GET",+ method: "POST",headers: { "Content-Type": "application/json" },- // body: JSON.stringify({ text: resume?.title }),+ body: JSON.stringify(resume),});if (!response.body) {@@ -66,11 +64,11 @@ const AiSection = () => {let done = false;setLoading(false);- while (!done && isStreaming) {+ while (!done) {const { value, done: doneReading } = await reader.read();done = doneReading;const chunk = decoder.decode(value, { stream: !done });- setAIContent((prev) => prev + chunk);+ setAIContent((prev: any) => prev + chunk);}} catch (error) {const message = "Error fetching resume review";@@ -104,16 +102,60 @@ const AiSection = () => {<SheetContent className="overflow-y-scroll"><SheetHeader><SheetTitle>AI Review</SheetTitle>- <SheetDescription>- {loading ? (- <div className="flex items-center flex-col">- <Loading />- <div>Loading...</div>+ {loading ? (+ <div className="flex items-center flex-col">+ <Loading />+ <div>Loading...</div>+ </div>+ ) : (+ <>+ <div className="pt-2">+ <h2>Score: {aIContent.score}</h2>+ </div>+ <div className="pt-2">+ <h2 className="font-semibold">Summary: </h2>+ <SheetDescription>+ <div>{aIContent?.summary}</div>+ </SheetDescription>+ </div>+ <div className="pt-2">+ <h2 className="font-semibold">Strengths: </h2>+ <SheetDescription>+ {/* <div>+ {aIContent?.strengths.map((s, i) => {+ return <li key={i}>{s}</li>;+ })}+ </div> */}+ </SheetDescription>+ </div>+ <div className="pt-2">+ <h2 className="font-semibold">Weaknesses: </h2>+ <SheetDescription>+ {/* <div>+ {aIContent?.weaknesses.map((w, i) => {+ return <li key={i}>{w}</li>;+ })}+ </div> */}+ </SheetDescription>+ </div>+ <div className="pt-2">+ <h2 className="font-semibold">Suggestions: </h2>+ <SheetDescription>+ {/* <div>+ {aIContent?.suggestions.map((s, i) => {+ return <li key={i}>{s}</li>;+ })}+ </div> */}+ </SheetDescription></div>- ) : (- aIContent- )}- </SheetDescription>+ <pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">+ <code className="text-white">+ {/* {JSON.stringify(data, null, 2)} */}+ {aIContent}+ </code>+ </pre>+ </>+ )}</SheetHeader></SheetContent></SheetPortal>diff --git a/src/components/TipTapContentViewer.tsx b/src/components/TipTapContentViewer.tsxnew file mode 100644index 0000000..1dda0ab--- /dev/null+++ b/src/components/TipTapContentViewer.tsx@@ -0,0 +1,16 @@+"use client";+import { Editor, EditorContent, useEditor } from "@tiptap/react";+import StarterKit from "@tiptap/starter-kit";+import { useEffect } from "react";++export const TipTapContentViewer = ({ content }: { content: string }) => {+ const editor = useEditor({+ extensions: [StarterKit],+ content: "",+ editable: false,+ });+ useEffect(() => {+ editor?.commands.setContent(content);+ });+ return <EditorContent editor={editor} />;+};diff --git a/src/components/myjobs/JobDetails.tsx b/src/components/myjobs/JobDetails.tsxindex ecfedf6..e94b57f 100644--- a/src/components/myjobs/JobDetails.tsx+++ b/src/components/myjobs/JobDetails.tsx@@ -10,20 +10,14 @@ import {} from "../ui/dialog";import { getJobDetails } from "@/actions/job.actions";import { format } from "date-fns";-import { EditorContent, useEditor } from "@tiptap/react";-import StarterKit from "@tiptap/starter-kit";import { Badge } from "../ui/badge";import { cn, formatUrl } from "@/lib/utils";import { JobResponse } from "@/models/job.model";import { toast } from "../ui/use-toast";+import { TipTapContentViewer } from "../TipTapContentViewer";function JobDetails({ jobId }: { jobId: string }) {const [job, setJob] = useState<JobResponse>();- const editor = useEditor({- extensions: [StarterKit],- content: "",- editable: false, // Make it non-editable if you only want to display content- });useEffect(() => {const getJob = async (id: string) => {const { job, success, message } = await getJobDetails(id);@@ -34,11 +28,10 @@ function JobDetails({ jobId }: { jobId: string }) {description: message,});}- editor?.commands.setContent(job.description);setJob(job);};getJob(jobId);- }, [jobId, editor]);+ }, [jobId]);return (<>@@ -82,11 +75,8 @@ function JobDetails({ jobId }: { jobId: string }) {</div>) : null}<div className="my-4">- <EditorContent editor={editor} />+ <TipTapContentViewer content={job?.description} /></div>- {/* <pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">- <code className="text-white">{JSON.stringify(job, null, 2)}</code>- </pre> */}<DialogFooter><DialogClose><Button variant="outline" className="mt-2 md:mt-0 w-full">diff --git a/src/components/profile/EducationCard.tsx b/src/components/profile/EducationCard.tsxindex cfdaf6f..a031b20 100644--- a/src/components/profile/EducationCard.tsx+++ b/src/components/profile/EducationCard.tsx@@ -10,8 +10,7 @@ import {import { Button } from "../ui/button";import { Edit } from "lucide-react";import { format } from "date-fns";-import { Editor, EditorContent } from "@tiptap/react";-import StarterKit from "@tiptap/starter-kit";+import { TipTapContentViewer } from "../TipTapContentViewer";interface EducationCardProps {educationSection: ResumeSection | undefined;@@ -54,19 +53,12 @@ function EducationCard({{education.endDate? format(education.endDate, "MMM yyyy"): "Present"}- <div>{education.location.label}</div>+ <br />+ {education.location.label}</CardDescription>{education.description ? (<div className="pt-2">- <EditorContent- editor={- new Editor({- extensions: [StarterKit],- content: education.description,- editable: false,- })- }- />+ <TipTapContentViewer content={education.description} /></div>) : null}</CardContent>diff --git a/src/components/profile/ExperienceCard.tsx b/src/components/profile/ExperienceCard.tsxindex eee998a..a6cfb86 100644--- a/src/components/profile/ExperienceCard.tsx+++ b/src/components/profile/ExperienceCard.tsx@@ -10,8 +10,7 @@ import {import { Button } from "../ui/button";import { Edit } from "lucide-react";import { format } from "date-fns";-import { Editor, EditorContent } from "@tiptap/react";-import StarterKit from "@tiptap/starter-kit";+import { TipTapContentViewer } from "../TipTapContentViewer";interface ExperienceCardProps {experienceSection: ResumeSection | undefined;@@ -52,18 +51,11 @@ function ExperienceCard({{experience.endDate? format(experience.endDate, "MMM yyyy"): "Present"}- <div>{experience.location.label}</div>+ <br />+ {experience.location.label}</CardDescription><div className="pt-2">- <EditorContent- editor={- new Editor({- extensions: [StarterKit],- content: experience.description,- editable: false,- })- }- />+ <TipTapContentViewer content={experience.description} /></div></CardContent></Card>diff --git a/src/components/profile/ResumeContainer.tsx b/src/components/profile/ResumeContainer.tsxindex b1b6f28..ca5b8eb 100644--- a/src/components/profile/ResumeContainer.tsx+++ b/src/components/profile/ResumeContainer.tsx@@ -53,7 +53,7 @@ function ResumeContainer({ resume }: { resume: Resume }) {<CardDescription>{resume?.title}</CardDescription><div className="flex items-center"><AddResumeSection resume={resume} ref={resumeSectionRef} />- <AiSection />+ <AiSection resume={resume} /></div></CardHeader></Card>diff --git a/src/components/profile/SummarySectionCard.tsx b/src/components/profile/SummarySectionCard.tsxindex a483ead..82eccba 100644--- a/src/components/profile/SummarySectionCard.tsx+++ b/src/components/profile/SummarySectionCard.tsx@@ -1,12 +1,8 @@-"use client";-import { Edit } from "lucide-react";import { Button } from "../ui/button";import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";import { ResumeSection } from "@/models/profile.model";-import { useEffect } from "react";-import { EditorContent, useEditor } from "@tiptap/react";-import StarterKit from "@tiptap/starter-kit";+import { TipTapContentViewer } from "../TipTapContentViewer";interface SummarySectionCardProps {summarySection: ResumeSection | undefined;@@ -17,14 +13,6 @@ function SummarySectionCard({summarySection,openDialogForEdit,}: SummarySectionCardProps) {- const editor = useEditor({- extensions: [StarterKit],- content: "",- editable: false,- });- useEffect(() => {- editor?.commands.setContent(summarySection?.summary?.content!);- });return (<><Card>@@ -43,7 +31,7 @@ function SummarySectionCard({</Button></CardHeader><CardContent>- <EditorContent editor={editor} />+ <TipTapContentViewer content={summarySection?.summary?.content!} /></CardContent></Card></>diff --git a/src/lib/utils.ts b/src/lib/utils.tsindex f10b5a9..3ae229f 100644--- a/src/lib/utils.ts+++ b/src/lib/utils.ts@@ -1,4 +1,5 @@import { type ClassValue, clsx } from "clsx";+import { NextApiRequest } from "next";import { twMerge } from "tailwind-merge";export function cn(...inputs: ClassValue[]) {diff --git a/src/models/ai.model.ts b/src/models/ai.model.tsnew file mode 100644index 0000000..ea2bb4d--- /dev/null+++ b/src/models/ai.model.ts@@ -0,0 +1,7 @@+export interface ResumeReviewResponse {+ summary: string;+ strengths: string[];+ weaknesses: string[];+ suggestions: string[];+ score: number;+}