express_backend / server /src /utils /aiAnalysis.ts
Joel Refuerzo
Initial commit: add client and server
50a7502
Raw History Blame Contribute Delete
1.44 kB
import OpenAI from "openai";
import { entryLevelPrompt } from "./prompt.js";
const token = process.env["GITHUB_TOKEN"];
const endpoint = "https://models.github.ai/inference";
const modelName = "openai/gpt-4o";
const openai = new OpenAI({ baseURL: endpoint, apiKey: token });
export async function analyzeResume(resumeImgUrl: string) {
const completion = await openai.chat.completions.create({
model: modelName,
temperature: 0.5,
messages: [
{
role: "system",
content: "You are a professional resume evaluator",
},
{
role: "user",
content: [
{
type: "text", text: entryLevelPrompt
},
{
type: "image_url",
image_url: {
"url": resumeImgUrl
}
}
]
},
],
response_format: { type: "json_object" },
});
// Parse and return the structured result
try {
const content = completion.choices[0].message.content;
if (!content) {{
return { error: "Empty response from AI" };
}}
return JSON.parse(content);
} catch (err) {
console.error("Failed to parse JSON:", err);
return { error: "Invalid JSON response", raw: completion.choices[0].message.content };
}
}