import {z} from 'zod' export type JudgeOutputType = 'REGRESSION' | 'CLASSIFICATION'; export type GetApiV1ObservabilityJudgesArgs = {type_filter?: (Array | null) | undefined, model_filter?: (Array | null) | undefined, page_size?: number | undefined, page?: number | undefined, q?: (string | null) | undefined}; export type GetApiV1ObservabilityJudgesOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const judgeClassificationOutputOption = z.object({value: z.string(), description: z.string()}); export const judgeClassificationOutput = z.object({type: z.literal("CLASSIFICATION").optional(), options: z.array(judgeClassificationOutputOption)}); export const judgeRegressionOutput = z.object({type: z.literal("REGRESSION").optional(), min: z.number().gte(0).optional(), min_description: z.string(), max: z.number().lt(1000000000).optional(), max_description: z.string()}); export const judge = z.object({id: z.string(), created_at: z.string(), updated_at: z.string(), deleted_at: z.string().nullable(), owner_id: z.string(), workspace_id: z.string(), name: z.string(), description: z.string(), model_name: z.string(), output: z.discriminatedUnion("type", [judgeClassificationOutput, judgeRegressionOutput]), instructions: z.string(), tools: z.array(z.string()), up_revision: z.string().nullable().optional(), down_revision: z.string().nullable().optional(), base_revision: z.string().nullable().optional()}); export const paginatedResultJudgePreview = z.object({results: z.array(judge).optional(), count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional()}); export const listJudgesResponse = z.object({judges: paginatedResultJudgePreview}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get judges with optional filtering and search * * GET /v1/observability/judges */ export const getApiV1ObservabilityJudges = async (args: GetApiV1ObservabilityJudgesArgs, options?: GetApiV1ObservabilityJudgesOptions) => { const {baseUrl = "https://api.mistral.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.type_filter ?? []) query.append("type_filter", String(item)) for (const item of args.model_filter ?? []) query.append("model_filter", String(item)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.page != null) query.append("page", String(args.page)) if (args.q != null) query.append("q", String(args.q)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/observability/judges${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(listJudgesResponse, await res.json()) };