Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions src/lib/resume-parser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { afterEach, describe, expect, it, vi } from "vitest";

afterEach(() => {
vi.unstubAllEnvs();
vi.resetModules();
});

describe("resume-parser module", () => {
it("can be imported without an OpenAI API key", async () => {
vi.stubEnv("OPENAI_API_KEY", "");

await expect(import("./resume-parser")).resolves.toHaveProperty(
"parseResumeFile"
);
});
});
11 changes: 8 additions & 3 deletions src/lib/resume-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ export interface ParsedResumeProfile {
};
}

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
function getOpenAIClient() {
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) {
throw new Error("OPENAI_API_KEY is not configured");
}
return new OpenAI({ apiKey });
}

// Use OpenAI to parse resume text into structured data
async function parseWithOpenAI(text: string): Promise<ParsedResumeProfile> {
Expand Down Expand Up @@ -82,6 +86,7 @@ Resume text:
${text}`;

try {
const openai = getOpenAIClient();
const response = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
Expand Down