Skip to content

Commit 5acd13a

Browse files
starfolkbotclaude
andcommitted
Migrate to Zod 4
Single-arg z.record(z.number()) -> z.record(z.string(), z.number()) in templates.ts (also fixes the choice_scores Record<number> inference in llm.ts), and replace the zod-4-incompatible zod-to-json-schema with native z.toJSONSchema in ragas.ts. Package typechecks cleanly under Zod 4. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f861688 commit 5acd13a

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

js/ragas.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,16 @@ import OpenAI from "openai";
109109
import { ListContains } from "./list";
110110
import { EmbeddingSimilarity } from "./string";
111111
import { z } from "zod";
112-
import zodToJsonSchema from "zod-to-json-schema";
113112
import { makePartial, ScorerWithPartial } from "./partial";
114113

114+
function zodToJsonSchema(schema: z.ZodType): Record<string, unknown> {
115+
return z.toJSONSchema(schema, {
116+
target: "draft-7",
117+
io: "input",
118+
unrepresentable: "any",
119+
});
120+
}
121+
115122
type RagasArgs = {
116123
input?: string;
117124
context?: string | string[];

js/templates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import translation from "../templates/translation.yaml";
1313

1414
export const modelGradedSpecSchema = z.object({
1515
prompt: z.string(),
16-
choice_scores: z.record(z.number()),
16+
choice_scores: z.record(z.string(), z.number()),
1717
model: z.string().optional(),
1818
use_cot: z.boolean().optional(),
1919
temperature: z.number().optional(),

0 commit comments

Comments
 (0)