| | |
| | import { authFetch } from "@/lib/api" |
| | import { CalculateWeightPayload, WeightBody } from "@/types/calculate" |
| | import { FilterFormValues } from "@/types/candidate-table" |
| |
|
| | const BASE_URL = "https://byteriot-candidateexplorer.hf.space/CandidateExplorer/agentic" |
| |
|
| | function toFilterBody(filters: FilterFormValues) { |
| | return { |
| | gpa_edu_1: filters.educations[0]?.gpa || null, |
| | univ_edu_1: filters.educations[0]?.university || null, |
| | major_edu_1: filters.educations[0]?.major || null, |
| | gpa_edu_2: filters.educations[1]?.gpa || null, |
| | univ_edu_2: filters.educations[1]?.university || null, |
| | major_edu_2: filters.educations[1]?.major || null, |
| | gpa_edu_3: filters.educations[2]?.gpa || null, |
| | univ_edu_3: filters.educations[2]?.university || null, |
| | major_edu_3: filters.educations[2]?.major || null, |
| | domicile: filters.domicile || null, |
| | yoe: filters.yoe || null, |
| | hardskills: filters.hardskills?.length ? [filters.hardskills] : null, |
| | softskills: filters.softskills?.length ? [filters.softskills] : null, |
| | certifications: filters.certifications?.length ? [filters.certifications] : null, |
| | business_domain: filters.businessDomain?.length ? [filters.businessDomain] : null, |
| | } |
| | } |
| |
|
| | function toWeightBody(value: CalculateWeightPayload): WeightBody { |
| | const edu = (i: number) => value.education[i] ?? { university: 0, major: 0, gpa: 0 } |
| | return { |
| | univ_edu_1: edu(0).university / 100, major_edu_1: edu(0).major / 100, gpa_edu_1: edu(0).gpa / 100, |
| | univ_edu_2: edu(1).university / 100, major_edu_2: edu(1).major / 100, gpa_edu_2: edu(1).gpa / 100, |
| | univ_edu_3: edu(2).university / 100, major_edu_3: edu(2).major / 100, gpa_edu_3: edu(2).gpa / 100, |
| | domicile: value.others.domicile / 100, |
| | yoe: value.others.yearOfExperiences / 100, |
| | hardskills: value.others.hardskills / 100, |
| | softskills: value.others.softskills / 100, |
| | certifications: value.others.certifications / 100, |
| | business_domain: value.others.businessDomain / 100, |
| | } |
| | } |
| |
|
| | async function postJSON(url: string, body?: unknown) { |
| | const res = await authFetch(url, { |
| | method: "POST", |
| | ...(body ? { body: JSON.stringify(body) } : {}), |
| | }) |
| | if (!res.ok) throw new Error(`Request failed: ${url} (${res.status})`) |
| | return res.json() |
| | } |
| |
|
| | export async function createAndCalculateScore( |
| | filters: FilterFormValues, |
| | weights: CalculateWeightPayload |
| | ): Promise<{ criteriaId: string }> { |
| | const res = await postJSON("/api/agentic", { |
| | filters, |
| | weights |
| | }) |
| | return { criteriaId: res.data.criteria_id } |
| | } |