Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/ragas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ import OpenAI from "openai";
import { ListContains } from "./list";
import { EmbeddingSimilarity } from "./string";
import { z } from "zod";
import zodToJsonSchema from "zod-to-json-schema";
import { zodToJsonSchema } from "./zod-utils";
import { makePartial, ScorerWithPartial } from "./partial";

type RagasArgs = {
Expand Down
22 changes: 22 additions & 0 deletions js/zod-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { zodToJsonSchema as zodToJsonSchemaV3 } from "zod-to-json-schema";
import * as z3 from "zod/v3";
import * as z4 from "zod/v4";

function isZodV4(zodObject: z3.ZodType | z4.ZodType): zodObject is z4.ZodType {
return (
typeof zodObject === "object" &&
zodObject !== null &&
"_zod" in zodObject &&
zodObject._zod !== undefined
);
}

export function zodToJsonSchema(schema: z4.ZodType | z3.ZodType) {
if (isZodV4(schema)) {
return z4.toJSONSchema(schema, {
target: "draft-7",
});
}

return zodToJsonSchemaV3(schema);
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"typedoc": "^0.25.13",
"typedoc-plugin-markdown": "^3.17.1",
"typescript": "^5.9.2",
"vitest": "^2.1.9"
"vitest": "^2.1.9",
"zod": "^3.25.34"
},
"dependencies": {
"ajv": "^8.17.1",
Expand All @@ -65,8 +66,10 @@
"linear-sum-assignment": "^1.0.7",
"mustache": "^4.2.0",
"openai": "^6.3.0",
"zod": "^3.25.76",
"zod-to-json-schema": "^3.24.6"
},
"peerDependencies": {
"zod": "^3.25.34 || ^4.0"
},
"packageManager": "pnpm@10.33.0"
}
Loading