@arizeai/phoenix-evals
Version:
A library for running evaluations for AI use cases
45 lines • 1.87 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createClassifier = createClassifier;
const generateClassification_1 = require("./generateClassification");
const template_1 = require("../template");
/**
* 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 createClassifier(args) {
const { model, choices, promptTemplate } = args, rest = __rest(args, ["model", "choices", "promptTemplate"]);
return async (args) => {
const templateVariables = Object.assign({}, args);
const prompt = (0, template_1.formatTemplate)({
template: promptTemplate,
variables: templateVariables,
});
const classification = await (0, generateClassification_1.generateClassification)(Object.assign({ model, labels: choicesToLabels(choices), prompt }, rest));
// Post-process the classification result and map it to the choices
const score = choices[classification.label];
return Object.assign({ score }, classification);
};
}
//# sourceMappingURL=createClassifier.js.map