Team Ai
Datasetpublic

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.

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes3.1kdownloads
function.test.ts262 linesDownload Raw Back to tests
1// @ts-ignore TS61332import { expect, test } from "vitest";3 4import * as z from "zod/v3";5import { util } from "../helpers/util.js";6 7const args1 = z.tuple([z.string()]);8const returns1 = z.number();9const func1 = z.function(args1, returns1);10 11test("function parsing", () => {12  const parsed = func1.parse((arg: any) => arg.length);13  const result = parsed("asdf");14  expect(result).toBe(4);15});16 17test("parsed function fail 1", () => {18  const parsed = func1.parse((x: string) => x);19  expect(() => parsed("asdf")).toThrow();20});21 22test("parsed function fail 2", () => {23  const parsed = func1.parse((x: string) => x);24  expect(() => parsed(13 as any)).toThrow();25});26 27test("function inference 1", () => {28  type func1 = z.TypeOf<typeof func1>;29  util.assertEqual<func1, (k: string) => number>(true);30});31 32test("method parsing", () => {33  const methodObject = z.object({34    property: z.number(),35    method: z.function().args(z.string()).returns(z.number()),36  });37  const methodInstance = {38    property: 3,39    method: function (s: string) {40      return s.length + this.property;41    },42  };43  const parsed = methodObject.parse(methodInstance);44  expect(parsed.method("length=8")).toBe(11); // 8 length + 3 property45});46 47test("async method parsing", async () => {48  const methodObject = z.object({49    property: z.number(),50    method: z.function().args(z.string()).returns(z.promise(z.number())),51  });52  const methodInstance = {53    property: 3,54    method: async function (s: string) {55      return s.length + this.property;56    },57  };58  const parsed = methodObject.parse(methodInstance);59  expect(await parsed.method("length=8")).toBe(11); // 8 length + 3 property60});61 62test("args method", () => {63  const t1 = z.function();64  type t1 = z.infer<typeof t1>;65  util.assertEqual<t1, (...args_1: unknown[]) => unknown>(true);66 67  const t2 = t1.args(z.string());68  type t2 = z.infer<typeof t2>;69  util.assertEqual<t2, (arg: string, ...args_1: unknown[]) => unknown>(true);70 71  const t3 = t2.returns(z.boolean());72  type t3 = z.infer<typeof t3>;73  util.assertEqual<t3, (arg: string, ...args_1: unknown[]) => boolean>(true);74});75 76const args2 = z.tuple([77  z.object({78    f1: z.number(),79    f2: z.string().nullable(),80    f3: z.array(z.boolean().optional()).optional(),81  }),82]);83const returns2 = z.union([z.string(), z.number()]);84 85const func2 = z.function(args2, returns2);86 87test("function inference 2", () => {88  type func2 = z.TypeOf<typeof func2>;89  util.assertEqual<90    func2,91    (arg: {92      f1: number;93      f2: string | null;94      f3?: (boolean | undefined)[] | undefined;95    }) => string | number96  >(true);97});98 99test("valid function run", () => {100  const validFunc2Instance = func2.validate((_x) => {101    return "adf" as any;102  });103 104  const checker = () => {105    validFunc2Instance({106      f1: 21,107      f2: "asdf",108      f3: [true, false],109    });110  };111 112  checker();113});114 115test("input validation error", () => {116  const invalidFuncInstance = func2.validate((_x) => {117    return "adf" as any;118  });119 120  const checker = () => {121    invalidFuncInstance("Invalid_input" as any);122  };123 124  expect(checker).toThrow();125});126 127test("output validation error", () => {128  const invalidFuncInstance = func2.validate((_x) => {129    return ["this", "is", "not", "valid", "output"] as any;130  });131 132  const checker = () => {133    invalidFuncInstance({134      f1: 21,135      f2: "asdf",136      f3: [true, false],137    });138  };139 140  expect(checker).toThrow();141});142 143z.function(z.tuple([z.string()])).args()._def.args;144 145test("special function error codes", () => {146  const checker = z.function(z.tuple([z.string()]), z.boolean()).implement((arg) => {147    return arg.length as any;148  });149  try {150    checker("12" as any);151  } catch (err) {152    const zerr = err as z.ZodError;153    const first = zerr.issues[0];154    if (first.code !== z.ZodIssueCode.invalid_return_type) throw new Error();155 156    expect(first.returnTypeError).toBeInstanceOf(z.ZodError);157  }158 159  try {160    checker(12 as any);161  } catch (err) {162    const zerr = err as z.ZodError;163    const first = zerr.issues[0];164    if (first.code !== z.ZodIssueCode.invalid_arguments) throw new Error();165    expect(first.argumentsError).toBeInstanceOf(z.ZodError);166  }167});168 169test("function with async refinements", async () => {170  const func = z171    .function()172    .args(z.string().refine(async (val) => val.length > 10))173    .returns(z.promise(z.number().refine(async (val) => val > 10)))174    .implement(async (val) => {175      return val.length;176    });177  const results = [];178  try {179    await func("asdfasdf");180    results.push("success");181  } catch (_err) {182    results.push("fail");183  }184  try {185    await func("asdflkjasdflkjsf");186    results.push("success");187  } catch (_err) {188    results.push("fail");189  }190 191  expect(results).toEqual(["fail", "success"]);192});193 194test("non async function with async refinements should fail", async () => {195  const func = z196    .function()197    .args(z.string().refine(async (val) => val.length > 10))198    .returns(z.number().refine(async (val) => val > 10))199    .implement((val) => {200      return val.length;201    });202 203  const results = [];204  try {205    await func("asdasdfasdffasdf");206    results.push("success");207  } catch (_err) {208    results.push("fail");209  }210 211  expect(results).toEqual(["fail"]);212});213 214test("allow extra parameters", () => {215  const maxLength5 = z216    .function()217    .args(z.string())218    .returns(z.boolean())219    .implement((str, _arg, _qewr) => {220      return str.length <= 5;221    });222 223  const filteredList = ["apple", "orange", "pear", "banana", "strawberry"].filter(maxLength5);224  expect(filteredList.length).toEqual(2);225});226 227test("params and returnType getters", () => {228  const func = z.function().args(z.string()).returns(z.string());229 230  const paramResult = func.parameters().items[0].parse("asdf");231  expect(paramResult).toBe("asdf");232 233  const returnResult = func.returnType().parse("asdf");234  expect(returnResult).toBe("asdf");235});236 237test("inference with transforms", () => {238  const funcSchema = z239    .function()240    .args(z.string().transform((val) => val.length))241    .returns(z.object({ val: z.number() }));242  const myFunc = funcSchema.implement((val) => {243    return { val, extra: "stuff" };244  });245  myFunc("asdf");246 247  util.assertEqual<typeof myFunc, (arg: string, ...args_1: unknown[]) => { val: number; extra: string }>(true);248});249 250test("fallback to OuterTypeOfFunction", () => {251  const funcSchema = z252    .function()253    .args(z.string().transform((val) => val.length))254    .returns(z.object({ arg: z.number() }).transform((val) => val.arg));255 256  const myFunc = funcSchema.implement((val) => {257    return { arg: val, arg2: false };258  });259 260  util.assertEqual<typeof myFunc, (arg: string, ...args_1: unknown[]) => number>(true);261});262 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai