From 3fc0507df7156da61c111807c2608cdbb71b8d85 Mon Sep 17 00:00:00 2001 From: Manu Goyal Date: Sun, 31 Mar 2024 15:02:23 -0700 Subject: [PATCH] Fix prompt params typespecs. (#168) After https://github.com/braintrustdata/braintrust-sdk/pull/166, we moved to using strict objects by default. Apparently creating intersections between two strict objects (e.g. `braintrustModelParamsSchema` and `openAIModelParamsSchema`) doesn't seem to work at all. We have to use `merge` to make everything work. See https://github.com/colinhacks/zod/issues/390 for an explanation of the issue. --- core/js/typespecs/prompt.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/core/js/typespecs/prompt.ts b/core/js/typespecs/prompt.ts index 030a57aa..01eb9619 100644 --- a/core/js/typespecs/prompt.ts +++ b/core/js/typespecs/prompt.ts @@ -95,21 +95,19 @@ const googleModelParamsSchema = z.strictObject({ }); const jsCompletionParamsSchema = z.strictObject({}); -export const modelParamsSchema = braintrustModelParamsSchema.and( - z.union([ - openAIModelParamsSchema, - anthropicModelParamsSchema, - googleModelParamsSchema, - jsCompletionParamsSchema, - ]) -); +export const modelParamsSchema = z.union([ + braintrustModelParamsSchema.merge(openAIModelParamsSchema), + braintrustModelParamsSchema.merge(anthropicModelParamsSchema), + braintrustModelParamsSchema.merge(googleModelParamsSchema), + braintrustModelParamsSchema.merge(jsCompletionParamsSchema), +]); export type ModelParams = z.infer; const anyModelParamsSchema = openAIModelParamsSchema - .and(anthropicModelParamsSchema) - .and(googleModelParamsSchema) - .and(braintrustModelParamsSchema); + .merge(anthropicModelParamsSchema) + .merge(googleModelParamsSchema) + .merge(braintrustModelParamsSchema); export type AnyModelParam = z.infer;