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
parse.js227 linesDownload Raw Back to lib
1import { getDeepObject } from './object-util.js';2import { defaultOptions } from './shared.js';3import { decodeURIComponent } from './decode-uri-component.js';4export const numberKeyDeserializer = (key) => {5    const asNumber = Number(key);6    if (!Number.isNaN(asNumber)) {7        return asNumber;8    }9    return key;10};11export const numberValueDeserializer = (value) => {12    const asNumber = Number(value);13    if (!Number.isNaN(asNumber)) {14        return asNumber;15    }16    return value;17};18const regexPlus = /\+/g;19const Empty = function () { };20Empty.prototype = Object.create(null);21function computeKeySlice(input, startIndex, endIndex, keyHasPlus, shouldDecodeKey) {22    let chunk = input.substring(startIndex, endIndex);23    if (keyHasPlus) {24        chunk = chunk.replace(regexPlus, ' ');25    }26    if (shouldDecodeKey) {27        chunk = decodeURIComponent(chunk) || chunk;28    }29    return chunk;30}31/**32 * Parses a query string into an object33 * @param {string} input34 * @param {ParseOptions=} options35 */36export function parse(input, options) {37    const { valueDeserializer = defaultOptions.valueDeserializer, keyDeserializer = defaultOptions.keyDeserializer, arrayRepeatSyntax = defaultOptions.arrayRepeatSyntax, nesting = defaultOptions.nesting, arrayRepeat = defaultOptions.arrayRepeat, nestingSyntax = defaultOptions.nestingSyntax, delimiter = defaultOptions.delimiter } = options ?? {};38    const charDelimiter = typeof delimiter === 'string' ? delimiter.charCodeAt(0) : delimiter;39    const isJsNestingSyntax = nestingSyntax === 'js';40    // Optimization: Use new Empty() instead of Object.create(null) for performance41    // v8 has a better optimization for initializing functions compared to Object42    const result = new Empty();43    if (typeof input !== 'string') {44        return result;45    }46    const inputLength = input.length;47    let value = '';48    let startingIndex = -1;49    let equalityIndex = -1;50    let keySeparatorIndex = -1;51    let currentObj = result;52    let lastKey = undefined;53    let currentKey = '';54    let keyChunk = '';55    let shouldDecodeKey = false;56    let shouldDecodeValue = false;57    let keyHasPlus = false;58    let valueHasPlus = false;59    let keyIsDot = false;60    let hasBothKeyValuePair = false;61    let c = 0;62    let arrayRepeatBracketIndex = -1;63    let prevIndex = -1;64    let prevChar = -1;65    // Have a boundary of input.length + 1 to access last pair inside the loop.66    for (let i = 0; i < inputLength + 1; i++) {67        c = i !== inputLength ? input.charCodeAt(i) : charDelimiter;68        // Handle '&' and end of line to pass the current values to result69        if (c === charDelimiter) {70            hasBothKeyValuePair = equalityIndex > startingIndex;71            // Optimization: Reuse equality index to store the end of key72            if (!hasBothKeyValuePair) {73                equalityIndex = i;74            }75            if (keySeparatorIndex !== equalityIndex - 1) {76                keyChunk = computeKeySlice(input, keySeparatorIndex + 1, arrayRepeatBracketIndex > -177                    ? arrayRepeatBracketIndex78                    : equalityIndex, keyHasPlus, shouldDecodeKey);79                currentKey = keyDeserializer(keyChunk);80                if (lastKey !== undefined) {81                    currentObj = getDeepObject(currentObj, lastKey, currentKey, isJsNestingSyntax && keyIsDot, undefined);82                }83            }84            // Add key/value pair only if the range size is greater than 1; a.k.a. contains at least "="85            if (hasBothKeyValuePair || currentKey !== '') {86                if (hasBothKeyValuePair) {87                    value = input.slice(equalityIndex + 1, i);88                    if (valueHasPlus) {89                        value = value.replace(regexPlus, ' ');90                    }91                    if (shouldDecodeValue) {92                        value = decodeURIComponent(value) || value;93                    }94                }95                const newValue = valueDeserializer(value, currentKey);96                if (arrayRepeat) {97                    const currentValue = currentObj[currentKey];98                    if (currentValue === undefined) {99                        if (arrayRepeatBracketIndex > -1) {100                            currentObj[currentKey] = [newValue];101                        }102                        else {103                            currentObj[currentKey] = newValue;104                        }105                    }106                    // Optimization: value.pop is faster than Array.isArray(value)107                    else if (currentValue.pop) {108                        currentValue.push(newValue);109                    }110                    else {111                        currentObj[currentKey] = [currentValue, newValue];112                    }113                }114                else115                    currentObj[currentKey] = newValue;116            }117            // Reset reading key value pairs118            value = '';119            startingIndex = i;120            equalityIndex = i;121            shouldDecodeKey = false;122            shouldDecodeValue = false;123            keyHasPlus = false;124            valueHasPlus = false;125            keyIsDot = false;126            arrayRepeatBracketIndex = -1;127            keySeparatorIndex = i;128            currentObj = result;129            lastKey = undefined;130            currentKey = '';131        }132        // Check ']'133        else if (c === 93) {134            if (arrayRepeat && arrayRepeatSyntax === 'bracket') {135                if (prevChar === 91) {136                    arrayRepeatBracketIndex = prevIndex;137                }138            }139            if (nesting &&140                (nestingSyntax === 'index' || isJsNestingSyntax) &&141                equalityIndex <= startingIndex) {142                if (keySeparatorIndex !== prevIndex) {143                    keyChunk = computeKeySlice(input, keySeparatorIndex + 1, i, keyHasPlus, shouldDecodeKey);144                    currentKey = keyDeserializer(keyChunk);145                    if (lastKey !== undefined) {146                        currentObj = getDeepObject(currentObj, lastKey, currentKey, undefined, undefined);147                    }148                    lastKey = currentKey;149                    keyHasPlus = false;150                    shouldDecodeKey = false;151                }152                keySeparatorIndex = i;153                keyIsDot = false;154            }155        }156        // Check '.'157        else if (c === 46) {158            if (nesting &&159                (nestingSyntax === 'dot' || isJsNestingSyntax) &&160                equalityIndex <= startingIndex) {161                if (keySeparatorIndex !== prevIndex) {162                    keyChunk = computeKeySlice(input, keySeparatorIndex + 1, i, keyHasPlus, shouldDecodeKey);163                    currentKey = keyDeserializer(keyChunk);164                    if (lastKey !== undefined) {165                        currentObj = getDeepObject(currentObj, lastKey, currentKey, isJsNestingSyntax);166                    }167                    lastKey = currentKey;168                    keyHasPlus = false;169                    shouldDecodeKey = false;170                }171                keyIsDot = true;172                keySeparatorIndex = i;173            }174        }175        // Check '['176        else if (c === 91) {177            if (nesting &&178                (nestingSyntax === 'index' || isJsNestingSyntax) &&179                equalityIndex <= startingIndex) {180                if (keySeparatorIndex !== prevIndex) {181                    keyChunk = computeKeySlice(input, keySeparatorIndex + 1, i, keyHasPlus, shouldDecodeKey);182                    currentKey = keyDeserializer(keyChunk);183                    if (isJsNestingSyntax && lastKey !== undefined) {184                        currentObj = getDeepObject(currentObj, lastKey, currentKey, isJsNestingSyntax);185                    }186                    lastKey = currentKey;187                    keyHasPlus = false;188                    shouldDecodeKey = false;189                    keyIsDot = false;190                }191                keySeparatorIndex = i;192            }193        }194        // Check '='195        else if (c === 61) {196            if (equalityIndex <= startingIndex) {197                equalityIndex = i;198            }199            // If '=' character occurs again, we should decode the input.200            else {201                shouldDecodeValue = true;202            }203        }204        // Check '+', and remember to replace it with empty space.205        else if (c === 43) {206            if (equalityIndex > startingIndex) {207                valueHasPlus = true;208            }209            else {210                keyHasPlus = true;211            }212        }213        // Check '%' character for encoding214        else if (c === 37) {215            if (equalityIndex > startingIndex) {216                shouldDecodeValue = true;217            }218            else {219                shouldDecodeKey = true;220            }221        }222        prevIndex = i;223        prevChar = c;224    }225    return result;226}227 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai