Skip to content

Commit

Permalink
Fix prompt params typespecs.
Browse files Browse the repository at this point in the history
After #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 colinhacks/zod#390 for an explanation of
the issue.
  • Loading branch information
manugoyal committed Mar 31, 2024
1 parent 5c6fe9d commit c711039
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions core/js/typespecs/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof modelParamsSchema>;

const anyModelParamsSchema = openAIModelParamsSchema
.and(anthropicModelParamsSchema)
.and(googleModelParamsSchema)
.and(braintrustModelParamsSchema);
.merge(anthropicModelParamsSchema)
.merge(googleModelParamsSchema)
.merge(braintrustModelParamsSchema);

export type AnyModelParam = z.infer<typeof anyModelParamsSchema>;

Expand Down

0 comments on commit c711039

Please sign in to comment.