Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1// @ts-ignore TS61332import { expect, test } from "vitest";3 4import * as z from "zod/v3";5import { util } from "../helpers/util.js";6 7const Test = z.object({8 f1: z.number(),9 f2: z.string().optional(),10 f3: z.string().nullable(),11 f4: z.array(z.object({ t: z.union([z.string(), z.boolean()]) })),12});13type TestFlattenedErrors = z.inferFlattenedErrors<typeof Test, { message: string; code: number }>;14type TestFormErrors = z.inferFlattenedErrors<typeof Test>;15 16test("default flattened errors type inference", () => {17 type TestTypeErrors = {18 formErrors: string[];19 fieldErrors: { [P in keyof z.TypeOf<typeof Test>]?: string[] };20 };21 22 util.assertEqual<z.inferFlattenedErrors<typeof Test>, TestTypeErrors>(true);23 util.assertEqual<z.inferFlattenedErrors<typeof Test, { message: string }>, TestTypeErrors>(false);24});25 26test("custom flattened errors type inference", () => {27 type ErrorType = { message: string; code: number };28 type TestTypeErrors = {29 formErrors: ErrorType[];30 fieldErrors: {31 [P in keyof z.TypeOf<typeof Test>]?: ErrorType[];32 };33 };34 35 util.assertEqual<z.inferFlattenedErrors<typeof Test>, TestTypeErrors>(false);36 util.assertEqual<z.inferFlattenedErrors<typeof Test, { message: string; code: number }>, TestTypeErrors>(true);37 util.assertEqual<z.inferFlattenedErrors<typeof Test, { message: string }>, TestTypeErrors>(false);38});39 40test("form errors type inference", () => {41 type TestTypeErrors = {42 formErrors: string[];43 fieldErrors: { [P in keyof z.TypeOf<typeof Test>]?: string[] };44 };45 46 util.assertEqual<z.inferFlattenedErrors<typeof Test>, TestTypeErrors>(true);47});48 49test(".flatten() type assertion", () => {50 const parsed = Test.safeParse({}) as z.SafeParseError<void>;51 const validFlattenedErrors: TestFlattenedErrors = parsed.error.flatten(() => ({ message: "", code: 0 }));52 // @ts-expect-error should fail assertion between `TestFlattenedErrors` and unmapped `flatten()`.53 const invalidFlattenedErrors: TestFlattenedErrors = parsed.error.flatten();54 const validFormErrors: TestFormErrors = parsed.error.flatten();55 // @ts-expect-error should fail assertion between `TestFormErrors` and mapped `flatten()`.56 const invalidFormErrors: TestFormErrors = parsed.error.flatten(() => ({57 message: "string",58 code: 0,59 }));60 61 [validFlattenedErrors, invalidFlattenedErrors, validFormErrors, invalidFormErrors];62});63 64test(".formErrors type assertion", () => {65 const parsed = Test.safeParse({}) as z.SafeParseError<void>;66 const validFormErrors: TestFormErrors = parsed.error.formErrors;67 // @ts-expect-error should fail assertion between `TestFlattenedErrors` and `.formErrors`.68 const invalidFlattenedErrors: TestFlattenedErrors = parsed.error.formErrors;69 70 [validFormErrors, invalidFlattenedErrors];71});72 73test("all errors", () => {74 const propertySchema = z.string();75 const schema = z76 .object({77 a: propertySchema,78 b: propertySchema,79 })80 .refine(81 (val) => {82 return val.a === val.b;83 },84 { message: "Must be equal" }85 );86 87 try {88 schema.parse({89 a: "asdf",90 b: "qwer",91 });92 } catch (error) {93 if (error instanceof z.ZodError) {94 expect(error.flatten()).toEqual({95 formErrors: ["Must be equal"],96 fieldErrors: {},97 });98 }99 }100 101 try {102 schema.parse({103 a: null,104 b: null,105 });106 } catch (_error) {107 const error = _error as z.ZodError;108 expect(error.flatten()).toEqual({109 formErrors: [],110 fieldErrors: {111 a: ["Expected string, received null"],112 b: ["Expected string, received null"],113 },114 });115 116 expect(error.flatten((iss) => iss.message.toUpperCase())).toEqual({117 formErrors: [],118 fieldErrors: {119 a: ["EXPECTED STRING, RECEIVED NULL"],120 b: ["EXPECTED STRING, RECEIVED NULL"],121 },122 });123 // Test identity124 125 expect(error.flatten((i: z.ZodIssue) => i)).toEqual({126 formErrors: [],127 fieldErrors: {128 a: [129 {130 code: "invalid_type",131 expected: "string",132 message: "Expected string, received null",133 path: ["a"],134 received: "null",135 },136 ],137 b: [138 {139 code: "invalid_type",140 expected: "string",141 message: "Expected string, received null",142 path: ["b"],143 received: "null",144 },145 ],146 },147 });148 // Test mapping149 expect(error.flatten((i: z.ZodIssue) => i.message.length)).toEqual({150 formErrors: [],151 fieldErrors: {152 a: ["Expected string, received null".length],153 b: ["Expected string, received null".length],154 },155 });156 }157});158 