Skip to content

Commit

Permalink
Removed levenshtein and made Evalite compatible with autoevals
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Dec 3, 2024
1 parent 853671b commit ab6850f
Show file tree
Hide file tree
Showing 16 changed files with 370 additions and 53 deletions.
8 changes: 7 additions & 1 deletion packages/evalite-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ export declare namespace Evalite {
};

export type Score = {
score: number;
/**
* A number between 0 and 1.
*
* Added null for compatibility with {@link https://github.com/braintrustdata/autoevals | autoevals}.
* null scores will be reported as 0.
*/
score: number | null;
name: string;
};

Expand Down
4 changes: 2 additions & 2 deletions packages/evalite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"dependencies": {
"table": "^6.8.2",
"commander": "^12.1.0",
"js-levenshtein": "^1.1.6",
"tinyrainbow": "^1.2.0",
"fastify": "^5.1.0",
"@fastify/websocket": "11.0.1",
Expand All @@ -33,6 +32,7 @@
"strip-ansi": "^7.1.0",
"@types/js-levenshtein": "^1.1.3",
"unstorage": "^1.13.1",
"ai": "^4.0.10"
"ai": "^4.0.10",
"autoevals": "^0.0.108"
}
}
33 changes: 0 additions & 33 deletions packages/evalite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Evalite } from "@evalite/core";
import levenshtein from "js-levenshtein";
import { inject, it } from "vitest";
import { reportTraceLocalStorage } from "./traces.js";

Expand Down Expand Up @@ -76,35 +75,3 @@ export const evalite = <TInput, TExpected>(
};
});
};

export const Levenshtein = (args: Evalite.ScoreInput<string>) => {
if (args.expected === undefined) {
throw new Error("LevenshteinScorer requires an expected value");
}

const [output, expected] = [`${args.output}`, `${args.expected}`];
const maxLen = Math.max(output.length, expected.length);

let score = 1;
if (maxLen > 0) {
score = 1 - levenshtein(output, expected) / maxLen;
}

return {
name: "Levenshtein",
score,
};
};

export const numericDifference = (args: Evalite.ScoreInput<number>) => {
if (args.expected === undefined) {
throw new Error("NumericDifferenceScorer requires an expected value");
}

return {
name: "NumericDifference",
score: 1 - Math.abs(args.output - args.expected) / args.expected,
};
};

export { reportTrace } from "./traces.js";
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { generateText } from "ai";
import { MockLanguageModelV1 } from "ai/test";
import { traceAISDKModel } from "../../../ai-sdk.js";
import { evalite, Levenshtein } from "../../../index.js";
import { evalite } from "../../../index.js";
import { Levenshtein } from "autoevals";

const model = new MockLanguageModelV1({
doGenerate: async () => ({
Expand Down
3 changes: 2 additions & 1 deletion packages/evalite/src/tests/fixtures/basics/basics.eval.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { evalite, Levenshtein } from "../../../index.js";
import { evalite } from "../../../index.js";
import { Levenshtein } from "autoevals";
import { setTimeout } from "node:timers/promises";

evalite("Basics", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { evalite, Levenshtein } from "../../../index.js";
import { evalite } from "../../../index.js";
import { Levenshtein } from "autoevals";

evalite("Failing", {
data: () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { evalite, Levenshtein } from "../../../index.js";
import { evalite } from "../../../index.js";
import { Levenshtein } from "autoevals";

evalite("Long Text", {
data: () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { evalite, Levenshtein } from "../../../index.js";
import { evalite } from "../../../index.js";
import { Levenshtein } from "autoevals";
import { setTimeout } from "node:timers/promises";

evalite("Much Data", {
Expand Down
3 changes: 2 additions & 1 deletion packages/evalite/src/tests/fixtures/multi/multi-1.eval.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { evalite, Levenshtein } from "../../../index.js";
import { evalite } from "../../../index.js";
import { Levenshtein } from "autoevals";
import { setTimeout } from "node:timers/promises";

evalite("Multiple 1", {
Expand Down
3 changes: 2 additions & 1 deletion packages/evalite/src/tests/fixtures/multi/multi-2.eval.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { evalite, Levenshtein } from "../../../index.js";
import { evalite } from "../../../index.js";
import { Levenshtein } from "autoevals";
import { setTimeout } from "node:timers/promises";

evalite("Multiple 2", {
Expand Down
3 changes: 2 additions & 1 deletion packages/evalite/src/tests/fixtures/multi/multi-3.eval.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { evalite, Levenshtein } from "../../../index.js";
import { evalite } from "../../../index.js";
import { Levenshtein } from "autoevals";
import { setTimeout } from "node:timers/promises";

evalite("Multiple 3", {
Expand Down
4 changes: 3 additions & 1 deletion packages/evalite/src/tests/fixtures/traces/traces.eval.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { evalite, Levenshtein, reportTrace } from "../../../index.js";
import { evalite } from "../../../index.js";
import { reportTrace } from "../../../traces.js";
import { Levenshtein } from "autoevals";

evalite("Traces", {
data: () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/evalite/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
},
"exclude": ["src/tests/playground"]
}
3 changes: 2 additions & 1 deletion packages/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"ai": "^3.4.33",
"@ai-sdk/openai": "0.0.72",
"dotenv": "^16.4.5",
"zod": "^3.23.8"
"zod": "^3.23.8",
"autoevals": "^0.0.108"
}
}
3 changes: 2 additions & 1 deletion packages/example/src/basics.eval.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";
import { evalite, Levenshtein } from "evalite";
import { evalite } from "evalite";
import { createStorage } from "unstorage";
import fsDriver from "unstorage/drivers/fs";
import { Levenshtein } from "autoevals";
import { cacheModel } from "./cache-model.js";

const storage = createStorage({
Expand Down
Loading

0 comments on commit ab6850f

Please sign in to comment.