UNPKG

@arizeai/phoenix-evals

Version:
60 lines 1.89 kB
import { getTemplateVariables } from "../template/index.js"; import { remapObject } from "../utils/objectMappingUtils.js"; import { createClassifierFn } from "./createClassifierFn.js"; import { LLMEvaluator } from "./LLMEvaluator.js"; /** * An LLM evaluator that performs evaluation via classification */ export class ClassificationEvaluator extends LLMEvaluator { evaluatorFn; promptTemplate; /** * A dynamically computed set of prompt template variables */ _promptTemplateVariables; /** * The model to use for classification */ model; /** * The choices to classify the example into */ choices; constructor(args) { super(args); this.promptTemplate = args.promptTemplate; this.model = args.model; this.choices = args.choices; this.evaluatorFn = createClassifierFn({ ...args, }); } evaluate = (example) => { return this.evaluatorFn(this.inputMapping ? remapObject(example, this.inputMapping) : example); }; /** * 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 = 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({ ...this, inputMapping, }); } } //# sourceMappingURL=ClassificationEvaluator.js.map