Spaces:
Build error
Build error
File size: 2,130 Bytes
c211499 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
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,
};
}
}
|