UNPKG

@arizeai/phoenix-evals

Version:
41 lines 1.27 kB
import { formatTemplate } from "../template/index.js"; import { generateClassification } from "./generateClassification.js"; /** * Convert a mapping of choices to labels * Asserts that the choices are valid */ function choicesToLabels(choices) { const labels = Object.keys(choices); if (labels.length < 1) { throw new Error("No choices provided"); } return labels; } /** * A function that serves as a factory that will output a classification evaluator function */ export function createClassifierFn(args) { const { model, choices, promptTemplate, ...rest } = args; return async (args) => { const templateVariables = { ...args, }; const prompt = formatTemplate({ template: promptTemplate, variables: templateVariables, }); const classification = await generateClassification({ model, labels: choicesToLabels(choices), prompt, ...rest, }); // Post-process the classification result and map it to the choices const score = choices[classification.label]; return { score, ...classification, }; }; } //# sourceMappingURL=createClassifierFn.js.map