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
1import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError.js";2import { getErrorMap } from "../errors.js";3import defaultErrorMap from "../locales/en.js";4import type { ZodParsedType } from "./util.js";5 6export const makeIssue = (params: {7 data: any;8 path: (string | number)[];9 errorMaps: ZodErrorMap[];10 issueData: IssueData;11}): ZodIssue => {12 const { data, path, errorMaps, issueData } = params;13 const fullPath = [...path, ...(issueData.path || [])];14 const fullIssue = {15 ...issueData,16 path: fullPath,17 };18 19 if (issueData.message !== undefined) {20 return {21 ...issueData,22 path: fullPath,23 message: issueData.message,24 };25 }26 27 let errorMessage = "";28 const maps = errorMaps29 .filter((m) => !!m)30 .slice()31 .reverse();32 for (const map of maps) {33 errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;34 }35 36 return {37 ...issueData,38 path: fullPath,39 message: errorMessage,40 };41};42 43export type ParseParams = {44 path: (string | number)[];45 errorMap: ZodErrorMap;46 async: boolean;47};48 49export type ParsePathComponent = string | number;50export type ParsePath = ParsePathComponent[];51export const EMPTY_PATH: ParsePath = [];52 53export interface ParseContext {54 readonly common: {55 readonly issues: ZodIssue[];56 readonly contextualErrorMap?: ZodErrorMap | undefined;57 readonly async: boolean;58 };59 readonly path: ParsePath;60 readonly schemaErrorMap?: ZodErrorMap | undefined;61 readonly parent: ParseContext | null;62 readonly data: any;63 readonly parsedType: ZodParsedType;64}65 66export type ParseInput = {67 data: any;68 path: (string | number)[];69 parent: ParseContext;70};71 72export function addIssueToContext(ctx: ParseContext, issueData: IssueData): void {73 const overrideMap = getErrorMap();74 const issue = makeIssue({75 issueData: issueData,76 data: ctx.data,77 path: ctx.path,78 errorMaps: [79 ctx.common.contextualErrorMap, // contextual error map is first priority80 ctx.schemaErrorMap, // then schema-bound map if available81 overrideMap, // then global override map82 overrideMap === defaultErrorMap ? undefined : defaultErrorMap, // then global default map83 ].filter((x) => !!x),84 });85 ctx.common.issues.push(issue);86}87 88export type ObjectPair = {89 key: SyncParseReturnType<any>;90 value: SyncParseReturnType<any>;91};92export class ParseStatus {93 value: "aborted" | "dirty" | "valid" = "valid";94 dirty(): void {95 if (this.value === "valid") this.value = "dirty";96 }97 abort(): void {98 if (this.value !== "aborted") this.value = "aborted";99 }100 101 static mergeArray(status: ParseStatus, results: SyncParseReturnType<any>[]): SyncParseReturnType {102 const arrayValue: any[] = [];103 for (const s of results) {104 if (s.status === "aborted") return INVALID;105 if (s.status === "dirty") status.dirty();106 arrayValue.push(s.value);107 }108 109 return { status: status.value, value: arrayValue };110 }111 112 static async mergeObjectAsync(113 status: ParseStatus,114 pairs: { key: ParseReturnType<any>; value: ParseReturnType<any> }[]115 ): Promise<SyncParseReturnType<any>> {116 const syncPairs: ObjectPair[] = [];117 for (const pair of pairs) {118 const key = await pair.key;119 const value = await pair.value;120 syncPairs.push({121 key,122 value,123 });124 }125 return ParseStatus.mergeObjectSync(status, syncPairs);126 }127 128 static mergeObjectSync(129 status: ParseStatus,130 pairs: {131 key: SyncParseReturnType<any>;132 value: SyncParseReturnType<any>;133 alwaysSet?: boolean;134 }[]135 ): SyncParseReturnType {136 const finalObject: any = {};137 for (const pair of pairs) {138 const { key, value } = pair;139 if (key.status === "aborted") return INVALID;140 if (value.status === "aborted") return INVALID;141 if (key.status === "dirty") status.dirty();142 if (value.status === "dirty") status.dirty();143 144 if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {145 finalObject[key.value] = value.value;146 }147 }148 149 return { status: status.value, value: finalObject };150 }151}152export interface ParseResult {153 status: "aborted" | "dirty" | "valid";154 data: any;155}156 157export type INVALID = { status: "aborted" };158export const INVALID: INVALID = Object.freeze({159 status: "aborted",160});161 162export type DIRTY<T> = { status: "dirty"; value: T };163export const DIRTY = <T>(value: T): DIRTY<T> => ({ status: "dirty", value });164 165export type OK<T> = { status: "valid"; value: T };166export const OK = <T>(value: T): OK<T> => ({ status: "valid", value });167 168export type SyncParseReturnType<T = any> = OK<T> | DIRTY<T> | INVALID;169export type AsyncParseReturnType<T> = Promise<SyncParseReturnType<T>>;170export type ParseReturnType<T> = SyncParseReturnType<T> | AsyncParseReturnType<T>;171 172export const isAborted = (x: ParseReturnType<any>): x is INVALID => (x as any).status === "aborted";173export const isDirty = <T>(x: ParseReturnType<T>): x is OK<T> | DIRTY<T> => (x as any).status === "dirty";174export const isValid = <T>(x: ParseReturnType<T>): x is OK<T> => (x as any).status === "valid";175export const isAsync = <T>(x: ParseReturnType<T>): x is AsyncParseReturnType<T> =>176 typeof Promise !== "undefined" && x instanceof Promise;177 