Skip to content

Commit dc76844

Browse files
chore: use transform to pass integer at the end
1 parent 6a78cfe commit dc76844

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/tools/mongodb/mongodbSchemas.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,10 @@ export const zVoyageModels = z
55
.enum(["voyage-3-large", "voyage-3.5", "voyage-3.5-lite", "voyage-code-3"])
66
.default("voyage-3-large");
77

8-
// Zod does not undestand JS boxed numbers (like Int32) as integer literals,
9-
// so we preprocess them to unwrap them so Zod understands them.
10-
function unboxNumber(v: unknown): number {
11-
if (v && typeof v === "object" && typeof v.valueOf === "function") {
12-
const n = Number(v.valueOf());
13-
if (!Number.isNaN(n)) return n;
14-
}
15-
return v as number;
16-
}
17-
188
export const zVoyageEmbeddingParameters = z.object({
199
outputDimension: z
20-
.preprocess(
21-
unboxNumber,
22-
z.union([z.literal("256"), z.literal("512"), z.literal("1024"), z.literal("2048"), z.literal("4096")])
23-
)
10+
.union([z.literal("256"), z.literal("512"), z.literal("1024"), z.literal("2048"), z.literal("4096")])
11+
.transform((value): number => Number.parseInt(value))
2412
.optional()
2513
.default("1024"),
2614
outputDtype: z.enum(["float", "int8", "uint8", "binary", "ubinary"]).optional().default("float"),

0 commit comments

Comments
 (0)