Spaces:
Sleeping
Sleeping
File size: 1,439 Bytes
50a7502 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 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 };
}
}
|