UNPKG

@arizeai/phoenix-evals

Version:

A library for running evaluations for AI use cases

41 lines 1.26 kB
import { generateClassification } from "./generateClassification.js"; import { formatTemplate } from "../template/index.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 */ export function createClassifier(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=createClassifier.js.map