Spaces:
Runtime error
Runtime error
File size: 3,251 Bytes
cd8bd0a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | import { z } from "zod";
import {
ACCOUNT_FALLBACK_STRATEGY_VALUES,
ROUTING_STRATEGY_VALUES,
} from "@/shared/constants/routingStrategies";
import { SUPPORTED_BATCH_ENDPOINTS } from "@/shared/constants/batchEndpoints";
import { MAX_REQUEST_BODY_LIMIT_MB, MIN_REQUEST_BODY_LIMIT_MB } from "@/shared/constants/bodySize";
import { COMBO_CONFIG_MODES } from "@/shared/constants/comboConfigMode";
import { providerAllowsOptionalApiKey } from "@/shared/constants/providers";
import { HIDEABLE_SIDEBAR_ITEM_IDS } from "@/shared/constants/sidebarVisibility";
import {
isForbiddenUpstreamHeaderName,
isForbiddenCustomHeaderName,
} from "@/shared/constants/upstreamHeaders";
import { MAX_TIMER_TIMEOUT_MS } from "@/shared/utils/runtimeTimeouts";
export const evalTargetSchema = z
.object({
type: z.enum(["suite-default", "model", "combo"]),
id: z.string().trim().min(1).optional().nullable(),
})
.superRefine((value, ctx) => {
if (value.type === "suite-default") {
return;
}
if (typeof value.id !== "string" || value.id.trim().length === 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "target.id is required for model and combo targets",
path: ["id"],
});
}
});
export const evalMessageSchema = z.object({
role: z.string().trim().min(1, "message.role is required").max(50),
content: z.string().trim().min(1, "message.content is required").max(20000),
});
export const evalCaseBuilderSchema = z.object({
id: z.string().trim().min(1).optional(),
name: z.string().trim().min(1, "case.name is required").max(200),
model: z.string().trim().min(1).max(300).optional().nullable(),
input: z.object({
messages: z.array(evalMessageSchema).min(1, "At least one message is required").max(32),
max_tokens: z.number().int().min(1).max(8192).optional(),
}),
expected: z.object({
strategy: z.enum(["contains", "exact", "regex"]),
value: z.string().trim().min(1, "expected.value is required").max(20000),
}),
tags: z.array(z.string().trim().min(1).max(64)).max(20).optional(),
});
export const evalRunSuiteSchema = z
.object({
suiteId: z.string().trim().min(1, "suiteId is required"),
outputs: z.record(z.string(), z.string()).optional(),
target: evalTargetSchema.optional(),
compareTarget: evalTargetSchema.optional(),
apiKeyId: z.string().trim().min(1, "apiKeyId must not be empty").optional(),
})
.superRefine((value, ctx) => {
if (value.compareTarget) {
const primaryType = value.target?.type || "suite-default";
const primaryId = value.target?.id?.trim() || "";
const compareId = value.compareTarget.id?.trim() || "";
if (primaryType === value.compareTarget.type && primaryId === compareId) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "compareTarget must differ from target",
path: ["compareTarget"],
});
}
}
});
export const evalSuiteSaveSchema = z.object({
id: z.string().trim().min(1).optional(),
name: z.string().trim().min(1, "name is required").max(200),
description: z.string().trim().max(2000).optional(),
cases: z.array(evalCaseBuilderSchema).min(1, "At least one case is required").max(200),
}); |