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 Parser from "./Parser";2import type {ParseNode, AnyParseNode, NodeType, UnsupportedCmdParseNode}3 from "./parseNode";4import type Options from "./Options";5import type {ArgType, BreakToken} from "./types";6import type {HtmlDomNode} from "./domTree";7import type {Token} from "./Token";8import type {MathDomNode} from "./mathMLTree";9 10/** Context provided to function handlers for error messages. */11export type FunctionContext = {12 funcName: string;13 parser: Parser;14 token?: Token;15 breakOnTokenText?: BreakToken;16};17 18export type FunctionHandler<NODETYPE extends NodeType> = (19 context: FunctionContext,20 args: AnyParseNode[],21 optArgs: (AnyParseNode | null | undefined)[],22) => UnsupportedCmdParseNode | ParseNode<NODETYPE>;23// Note: reverse the order of the return type union will cause a flow error.24// See https://github.com/facebook/flow/issues/3663.25 26export type HtmlBuilder<NODETYPE extends NodeType> =27 (group: ParseNode<NODETYPE>, options: Options) => HtmlDomNode;28export type MathMLBuilder<NODETYPE extends NodeType> =29 (group: ParseNode<NODETYPE>, options: Options) => MathDomNode;30 31// More general version of `HtmlBuilder` for nodes (e.g. \sum, accent types)32// whose presence impacts super/subscripting. In this case, ParseNode<"supsub">33// delegates its HTML building to the HtmlBuilder corresponding to these nodes.34export type HtmlBuilderSupSub<NODETYPE extends NodeType> =35 (group: ParseNode<"supsub"> | ParseNode<NODETYPE>, options: Options) => HtmlDomNode;36 37export type FunctionPropSpec = {38 // The number of arguments the function takes.39 numArgs: number;40 41 // An array corresponding to each argument of the function, giving the42 // type of argument that should be parsed. Its length should be equal43 // to `numOptionalArgs + numArgs`, and types for optional arguments44 // should appear before types for mandatory arguments.45 argTypes?: ArgType[];46 47 // Whether it expands to a single token or a braced group of tokens.48 // If it's grouped, it can be used as an argument to primitive commands,49 // such as \sqrt (without the optional argument) and super/subscript.50 allowedInArgument?: boolean;51 52 // Whether or not the function is allowed inside text mode53 // (default false)54 allowedInText?: boolean;55 56 // Whether or not the function is allowed inside text mode57 // (default true)58 allowedInMath?: boolean;59 60 // (optional) The number of optional arguments the function61 // should parse. If the optional arguments aren't found,62 // `null` will be passed to the handler in their place.63 // (default 0)64 numOptionalArgs?: number;65 66 // Must be true if the function is an infix operator.67 infix?: boolean;68 69 // Whether or not the function is a TeX primitive.70 primitive?: boolean;71};72 73type FunctionDefSpec<NODETYPE extends NodeType> = {74 // Unique string to differentiate parse nodes.75 // Also determines the type of the value returned by `handler`.76 type: NODETYPE;77 78 // The first argument to defineFunction is a single name or a list of names.79 // All functions named in such a list will share a single implementation.80 names: Array<string>;81 82 // Properties that control how the functions are parsed.83 props: FunctionPropSpec;84 85 // The handler is called to handle these functions and their arguments and86 // returns a `ParseNode`.87 handler: FunctionHandler<NODETYPE> | null | undefined;88 89 // This function returns an object representing the DOM structure to be90 // created when rendering the defined LaTeX function.91 // This should not modify the `ParseNode`.92 htmlBuilder?: HtmlBuilder<NODETYPE>;93 94 // This function returns an object representing the MathML structure to be95 // created when rendering the defined LaTeX function.96 // This should not modify the `ParseNode`.97 mathmlBuilder?: MathMLBuilder<NODETYPE>;98};99 100/**101 * Final function spec for use at parse time.102 * This is almost identical to `FunctionPropSpec`, except it103 * 1. includes the function handler, and104 * 2. requires all arguments except argTypes.105 * It is generated by `defineFunction()` below.106 */107export type FunctionSpec<NODETYPE extends NodeType> = {108 type: NODETYPE; // Need to use the type to avoid error. See NOTES below.109 numArgs: number;110 argTypes?: ArgType[];111 allowedInArgument: boolean;112 allowedInText: boolean;113 allowedInMath: boolean;114 numOptionalArgs: number;115 infix: boolean;116 primitive: boolean;117 118 // FLOW TYPE NOTES: Doing either one of the following two119 //120 // - removing the NODETYPE type parameter in FunctionSpec above;121 // - using ?FunctionHandler<NODETYPE> below;122 //123 // results in a confusing flow typing error:124 // "string literal `styling`. This type is incompatible with..."125 // pointing to the definition of `defineFunction` and finishing with126 // "some incompatible instantiation of `NODETYPE`"127 //128 // Having FunctionSpec<NODETYPE> above and FunctionHandler<*> below seems to129 // circumvent this error. This is not harmful for catching errors since130 // _functions is typed FunctionSpec<*> (it stores all TeX function specs).131 132 // Must be specified unless it's handled directly in the parser.133 handler: FunctionHandler<NodeType> | null | undefined;134};135 136/**137 * All registered functions.138 * `functions.js` just exports this same dictionary again and makes it public.139 * `Parser.js` requires this dictionary.140 */141export const _functions: Record<string, FunctionSpec<NodeType>> = {};142 143/**144 * All HTML builders. Should be only used in the `define*` and the `build*ML`145 * functions.146 *147 * Builders for different node types are stored side by side, but148 * `HtmlBuilder<T>` is contravariant in `T`, so there is no single type149 * argument that makes storing/retrieving them typecheck. `any` is used150 * as an existential-quantifier escape hatch.151 */152// eslint-disable-next-line @typescript-eslint/no-explicit-any153export const _htmlGroupBuilders: Record<string, HtmlBuilder<any>> = {};154 155/**156 * All MathML builders. Should be only used in the `define*` and the `build*ML`157 * functions. See `_htmlGroupBuilders` above for the rationale behind `any`.158 */159// eslint-disable-next-line @typescript-eslint/no-explicit-any160export const _mathmlGroupBuilders: Record<string, MathMLBuilder<any>> = {};161 162export default function defineFunction<NODETYPE extends NodeType>({163 type,164 names,165 props,166 handler,167 htmlBuilder,168 mathmlBuilder,169}: FunctionDefSpec<NODETYPE>) {170 // Set default values of functions171 const data = {172 type,173 numArgs: props.numArgs,174 argTypes: props.argTypes,175 allowedInArgument: !!props.allowedInArgument,176 allowedInText: !!props.allowedInText,177 allowedInMath: (props.allowedInMath === undefined)178 ? true179 : props.allowedInMath,180 numOptionalArgs: props.numOptionalArgs || 0,181 infix: !!props.infix,182 primitive: !!props.primitive,183 handler,184 };185 for (let i = 0; i < names.length; ++i) {186 _functions[names[i]] = data;187 }188 if (type) {189 if (htmlBuilder) {190 _htmlGroupBuilders[type] = htmlBuilder;191 }192 if (mathmlBuilder) {193 _mathmlGroupBuilders[type] = mathmlBuilder;194 }195 }196}197 198/**199 * Use this to register only the HTML and MathML builders for a function (e.g.200 * if the function's ParseNode is generated in Parser.js rather than via a201 * stand-alone handler provided to `defineFunction`).202 */203export function defineFunctionBuilders<NODETYPE extends NodeType>({204 type, htmlBuilder, mathmlBuilder,205}: {206 type: NODETYPE;207 htmlBuilder?: HtmlBuilder<NODETYPE>;208 mathmlBuilder: MathMLBuilder<NODETYPE>;209}) {210 defineFunction({211 type,212 names: [],213 props: {numArgs: 0},214 handler() { throw new Error('Should never be called.'); },215 htmlBuilder,216 mathmlBuilder,217 });218}219 220export const normalizeArgument = function(arg: AnyParseNode): AnyParseNode {221 return arg.type === "ordgroup" && arg.body.length === 1 ? arg.body[0] : arg;222};223 224// Since the corresponding buildHTML/buildMathML function expects a225// list of elements, we normalize for different kinds of arguments226export const ordargument = function(arg: AnyParseNode): AnyParseNode[] {227 return arg.type === "ordgroup" ? arg.body : [arg];228};229 