MCPcopy Create free account
hub / github.com/anomalyco/models.dev / refineModel

Function refineModel

packages/core/src/schema.ts:275–321  ·  view source on GitHub ↗
(schema: T)

Source from the content-addressed store, hash-verified

273});
274
275function refineModel<T extends z.ZodTypeAny>(schema: T) {
276 return schema
277 .refine(
278 (data) => {
279 return data.reasoning !== true || data.reasoning_options !== undefined;
280 },
281 {
282 message: "Must set reasoning_options when reasoning is true",
283 path: ["reasoning_options"],
284 },
285 )
286 .refine(
287 (data) => {
288 return data.reasoning !== false || data.reasoning_options === undefined;
289 },
290 {
291 message: "Cannot set reasoning_options when reasoning is false",
292 path: ["reasoning_options"],
293 },
294 )
295 .refine(
296 (data) => {
297 return !(
298 data.reasoning === false && data.cost?.reasoning !== undefined
299 );
300 },
301 {
302 message: "Cannot set cost.reasoning when reasoning is false",
303 path: ["cost", "reasoning"],
304 },
305 )
306 .refine(
307 (data) => {
308 const tiers = data.cost?.tiers;
309 if (tiers === undefined) return true;
310
311 const sizes = tiers.map(
312 (tier: { tier: { size: number } }) => tier.tier.size,
313 );
314 return new Set(sizes).size === sizes.length;
315 },
316 {
317 message: "Cost context tiers must not have duplicate sizes",
318 path: ["cost", "tiers"],
319 },
320 );
321}
322
323export const ModelShape = z
324 .object({

Callers 1

schema.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected