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/**2 * Checks if two arrays are equal by comparing their values.3 */4export function arraysAreEqual(arr1, arr2) {5 if (arr1.length !== arr2.length)6 return false;7 return arr1.every((value, index) => isEqual(value, arr2[index]));8}9/**10 * A utility function that compares two values for equality.11 */12function isEqual(a, b) {13 if (Number.isNaN(a) && Number.isNaN(b))14 return true;15 if (Array.isArray(a) && Array.isArray(b))16 return arraysAreEqual(a, b);17 if (typeof a === "object" && typeof b === "object")18 return isDeepEqual(a, b);19 return Object.is(a, b);20}21/**22 * A utility function that compares two values for deep equality.23 */24function isDeepEqual(a, b) {25 if (typeof a !== "object" || typeof b !== "object" || a === null || b === null)26 return false;27 const aKeys = Object.keys(a);28 const bKeys = Object.keys(b);29 if (aKeys.length !== bKeys.length)30 return false;31 for (const key of aKeys) {32 if (!bKeys.includes(key))33 return false;34 if (!isEqual(a[key], b[key])) {35 return false;36 }37 }38 return true;39}40/**41 * Splits an array into chunks of a given size.42 * @param arr The array to split.43 * @param size The size of each chunk.44 * @returns An array of arrays, where each sub-array has `size` elements from the original array.45 * @example ```ts46 * const arr = [1, 2, 3, 4, 5, 6, 7, 8];47 * const chunks = chunk(arr, 3);48 * // chunks = [[1, 2, 3], [4, 5, 6], [7, 8]]49 * ```50 */51export function chunk(arr, size) {52 if (size <= 0)53 return [];54 const result = [];55 for (let i = 0; i < arr.length; i += size) {56 result.push(arr.slice(i, i + size));57 }58 return result;59}60/**61 * Checks if the given index is valid for the given array.62 *63 * @param index - The index to check64 * @param arr - The array to check65 */66export function isValidIndex(index, arr) {67 return index >= 0 && index < arr.length;68}69/**70 * Returns the array element after the given index, or undefined for out-of-bounds or empty arrays.71 * @param array the array.72 * @param index the index of the current element.73 * @param loop loop to the beginning of the array if the next index is out of bounds?74 */75/**76 * Returns the array element after the given index, or undefined for out-of-bounds or empty arrays.77 * For single-element arrays, returns the element if the index is 0.78 * @param array the array.79 * @param index the index of the current element.80 * @param loop loop to the beginning of the array if the next index is out of bounds?81 */82export function next(array, index, loop = true) {83 if (array.length === 0 || index < 0 || index >= array.length)84 return;85 if (array.length === 1 && index === 0)86 return array[0];87 if (index === array.length - 1)88 return loop ? array[0] : undefined;89 return array[index + 1];90}91/**92 * Returns the array element prior to the given index, or undefined for out-of-bounds or empty arrays.93 * For single-element arrays, returns the element if the index is 0.94 * @param array the array.95 * @param index the index of the current element.96 * @param loop loop to the end of the array if the previous index is out of bounds?97 */98export function prev(array, index, loop = true) {99 if (array.length === 0 || index < 0 || index >= array.length)100 return;101 if (array.length === 1 && index === 0)102 return array[0];103 if (index === 0)104 return loop ? array[array.length - 1] : undefined;105 return array[index - 1];106}107/**108 * Returns the element some number after the given index. If the target index is out of bounds:109 * - If looping is disabled, the first or last element will be returned.110 * - If looping is enabled, it will wrap around the array.111 * Returns undefined for empty arrays or out-of-bounds initial indices.112 * @param array the array.113 * @param index the index of the current element.114 * @param increment the number of elements to move forward (can be negative).115 * @param loop loop around the array if the target index is out of bounds?116 */117export function forward(array, index, increment, loop = true) {118 if (array.length === 0 || index < 0 || index >= array.length)119 return;120 let targetIndex = index + increment;121 if (loop) {122 // Ensure positive modulus123 targetIndex = ((targetIndex % array.length) + array.length) % array.length;124 }125 else {126 // Clamp to array bounds when not looping127 targetIndex = Math.max(0, Math.min(targetIndex, array.length - 1));128 }129 return array[targetIndex];130}131/**132 * Returns the element some number before the given index. If the target index is out of bounds:133 * - If looping is disabled, the first or last element will be returned.134 * - If looping is enabled, it will wrap around the array.135 * Returns undefined for empty arrays or out-of-bounds initial indices.136 * @param array the array.137 * @param index the index of the current element.138 * @param decrement the number of elements to move backward (can be negative).139 * @param loop loop around the array if the target index is out of bounds?140 */141export function backward(array, index, decrement, loop = true) {142 if (array.length === 0 || index < 0 || index >= array.length)143 return;144 let targetIndex = index - decrement;145 if (loop) {146 // Ensure positive modulus147 targetIndex = ((targetIndex % array.length) + array.length) % array.length;148 }149 else {150 // Clamp to array bounds when not looping151 targetIndex = Math.max(0, Math.min(targetIndex, array.length - 1));152 }153 return array[targetIndex];154}155/**156 * Finds the next matching item from a list of values based on a search string.157 *158 * This function handles several special cases in typeahead behavior:159 *160 * 1. Space handling: When a search string ends with a space, it handles it specially:161 * - If there's only one match for the text before the space, it ignores the space162 * - If there are multiple matches and the current match already starts with the search prefix163 * followed by a space, it keeps the current match (doesn't change selection on space)164 * - Only after typing characters beyond the space will it move to a more specific match165 *166 * 2. Repeated character handling: If a search consists of repeated characters (e.g., "aaa"),167 * it treats it as a single character for matching purposes168 *169 * 3. Cycling behavior: The function wraps around the values array starting from the current match170 * to find the next appropriate match, creating a cycling selection behavior171 *172 * @param values - Array of string values to search through (e.g., the text content of menu items)173 * @param search - The current search string typed by the user174 * @param currentMatch - The currently selected/matched item, if any175 * @returns The next matching value that should be selected, or undefined if no match is found176 */177export function getNextMatch(values, search, currentMatch) {178 const lowerSearch = search.toLowerCase();179 if (lowerSearch.endsWith(" ")) {180 const searchWithoutSpace = lowerSearch.slice(0, -1);181 const matchesWithoutSpace = values.filter((value) => value.toLowerCase().startsWith(searchWithoutSpace));182 /**183 * If there's only one match for the prefix without space, we don't184 * watch to match with space.185 */186 if (matchesWithoutSpace.length <= 1) {187 return getNextMatch(values, searchWithoutSpace, currentMatch);188 }189 const currentMatchLowercase = currentMatch?.toLowerCase();190 /**191 * If the current match already starts with the search prefix and has a space afterward,192 * and the user has only typed up to that space, keep the current match until they193 * disambiguate.194 */195 if (currentMatchLowercase &&196 currentMatchLowercase.startsWith(searchWithoutSpace) &&197 currentMatchLowercase.charAt(searchWithoutSpace.length) === " " &&198 search.trim() === searchWithoutSpace) {199 return currentMatch;200 }201 /**202 * With multiple matches, find items that match the full search string with space203 */204 const spacedMatches = values.filter((value) => value.toLowerCase().startsWith(lowerSearch));205 /**206 * If we found matches with the space, use the first one that's not the current match207 */208 if (spacedMatches.length > 0) {209 const currentMatchIndex = currentMatch ? values.indexOf(currentMatch) : -1;210 let wrappedMatches = wrapArray(spacedMatches, Math.max(currentMatchIndex, 0));211 // return the first match that is not the current one.212 const nextMatch = wrappedMatches.find((match) => match !== currentMatch);213 // fallback to current if no other is found.214 return nextMatch || currentMatch;215 }216 }217 const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);218 const normalizedSearch = isRepeated ? search[0] : search;219 const normalizedLowerSearch = normalizedSearch.toLowerCase();220 const currentMatchIndex = currentMatch ? values.indexOf(currentMatch) : -1;221 let wrappedValues = wrapArray(values, Math.max(currentMatchIndex, 0));222 const excludeCurrentMatch = normalizedSearch.length === 1;223 if (excludeCurrentMatch)224 wrappedValues = wrappedValues.filter((v) => v !== currentMatch);225 const nextMatch = wrappedValues.find((value) => value?.toLowerCase().startsWith(normalizedLowerSearch));226 return nextMatch !== currentMatch ? nextMatch : undefined;227}228/**229 * Wraps an array around itself at a given start index230 * Example: `wrapArray(['a', 'b', 'c', 'd'], 2) === ['c', 'd', 'a', 'b']`231 */232export function wrapArray(array, startIndex) {233 return array.map((_, index) => array[(startIndex + index) % array.length]);234}235 