Spaces:
Sleeping
Sleeping
Download server/src/utils/aiAnalysis.ts from Leoj030/express_backend: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/spaces/Leoj030/express_backend/resolve/main/server/src/utils/aiAnalysis.ts
- Command line
-
hf download hf://spaces/Leoj030/express_backend/server/src/utils/aiAnalysis.ts
-
curl -L -o aiAnalysis.ts https://huggingface.co/spaces/Leoj030/express_backend/resolve/main/server/src/utils/aiAnalysis.ts
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 }; | |
| } | |
| } | |