UNPKG

@arizeai/phoenix-evals

Version:
45 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClassificationEvaluator = void 0; const template_1 = require("../template"); const objectMappingUtils_1 = require("../utils/objectMappingUtils"); const createClassifierFn_1 = require("./createClassifierFn"); const LLMEvaluator_1 = require("./LLMEvaluator"); /** * An LLM evaluator that performs evaluation via classification */ class ClassificationEvaluator extends LLMEvaluator_1.LLMEvaluator { constructor(args) { super(args); this.evaluate = (example) => { return this.evaluatorFn(this.inputMapping ? (0, objectMappingUtils_1.remapObject)(example, this.inputMapping) : example); }; this.promptTemplate = args.promptTemplate; this.model = args.model; this.choices = args.choices; this.evaluatorFn = (0, createClassifierFn_1.createClassifierFn)(Object.assign({}, args)); } /** * List out the prompt template variables needed to perform evaluation */ get promptTemplateVariables() { // Use dynamic programming to see if it's computed already if (!Array.isArray(this._promptTemplateVariables)) { this._promptTemplateVariables = (0, template_1.getTemplateVariables)({ template: this.promptTemplate, }); } // Give a copy of the variables return [...this._promptTemplateVariables]; } /** * Binds the input mapping to the evaluator. It makes a a copy of the evaluator and returns it. */ bindInputMapping(inputMapping) { return new ClassificationEvaluator(Object.assign(Object.assign({}, this), { inputMapping })); } } exports.ClassificationEvaluator = ClassificationEvaluator; //# sourceMappingURL=ClassificationEvaluator.js.map