1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- export class StringEvaluator {
- constructor(params) {
- Object.defineProperty(this, "evaluationName", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "inputKey", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "predictionKey", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "answerKey", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "gradingFunction", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- this.evaluationName = params.evaluationName;
- this.inputKey = params.inputKey ?? "input";
- this.predictionKey = params.predictionKey ?? "output";
- this.answerKey =
- params.answerKey !== undefined ? params.answerKey : "output";
- this.gradingFunction = params.gradingFunction;
- }
- async evaluateRun(run, example) {
- if (!run.outputs) {
- throw new Error("Run outputs cannot be undefined.");
- }
- const functionInputs = {
- input: run.inputs[this.inputKey],
- prediction: run.outputs[this.predictionKey],
- answer: this.answerKey ? example?.outputs?.[this.answerKey] : null,
- };
- const gradingResults = await this.gradingFunction(functionInputs);
- const key = gradingResults.key || this.evaluationName;
- if (!key) {
- throw new Error("Evaluation name cannot be undefined.");
- }
- return {
- key,
- score: gradingResults.score,
- value: gradingResults.value,
- comment: gradingResults.comment,
- correction: gradingResults.correction,
- };
- }
- }
|