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.
03k
1const path = require('path');2const fs = require('fs');3const Keyv = require('keyv');4const { writeJSON, tryParse } = require('./utils');5const { del } = require('./del');6 7const cache = {8 /**9 * Load a cache identified by the given Id. If the element does not exists, then initialize an empty10 * cache storage. If specified `cacheDir` will be used as the directory to persist the data to. If omitted11 * then the cache module directory `./cache` will be used instead12 *13 * @method load14 * @param docId {String} the id of the cache, would also be used as the name of the file cache15 * @param [cacheDir] {String} directory for the cache entry16 */17 load: function (docId, cacheDir) {18 const me = this;19 me.keyv = new Keyv();20 21 me.__visited = {};22 me.__persisted = {};23 24 me._pathToFile = cacheDir ? path.resolve(cacheDir, docId) : path.resolve(__dirname, '../.cache/', docId);25 26 if (fs.existsSync(me._pathToFile)) {27 me._persisted = tryParse(me._pathToFile, {});28 }29 },30 31 get _persisted() {32 return this.__persisted;33 },34 35 set _persisted(value) {36 this.__persisted = value;37 },38 39 get _visited() {40 return this.__visited;41 },42 43 set _visited(value) {44 this.__visited = value;45 },46 47 /**48 * Load the cache from the provided file49 * @method loadFile50 * @param {String} pathToFile the path to the file containing the info for the cache51 */52 loadFile: function (pathToFile) {53 const me = this;54 const dir = path.dirname(pathToFile);55 const fName = path.basename(pathToFile);56 57 me.load(fName, dir);58 },59 60 /**61 * Returns the entire persisted object62 * @method all63 * @returns {*}64 */65 all: function () {66 return this._persisted;67 },68 69 keys: function () {70 return Object.keys(this._persisted);71 },72 /**73 * sets a key to a given value74 * @method setKey75 * @param key {string} the key to set76 * @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify77 */78 setKey: function (key, value) {79 this._visited[key] = true;80 this._persisted[key] = value;81 },82 /**83 * remove a given key from the cache84 * @method removeKey85 * @param key {String} the key to remove from the object86 */87 removeKey: function (key) {88 delete this._visited[key]; // esfmt-ignore-line89 delete this._persisted[key]; // esfmt-ignore-line90 },91 /**92 * Return the value of the provided key93 * @method getKey94 * @param key {String} the name of the key to retrieve95 * @returns {*} the value from the key96 */97 getKey: function (key) {98 this._visited[key] = true;99 return this._persisted[key];100 },101 102 /**103 * Remove keys that were not accessed/set since the104 * last time the `prune` method was called.105 * @method _prune106 * @private107 */108 _prune: function () {109 const me = this;110 const obj = {};111 112 const keys = Object.keys(me._visited);113 114 // no keys visited for either get or set value115 if (keys.length === 0) {116 return;117 }118 119 keys.forEach(function (key) {120 obj[key] = me._persisted[key];121 });122 123 me._visited = {};124 me._persisted = obj;125 },126 127 /**128 * Save the state of the cache identified by the docId to disk129 * as a JSON structure130 * @param [noPrune=false] {Boolean} whether to remove from cache the non visited files131 * @method save132 */133 save: function (noPrune) {134 const me = this;135 !noPrune && me._prune();136 writeJSON(me._pathToFile, me._persisted);137 },138 139 /**140 * remove the file where the cache is persisted141 * @method removeCacheFile142 * @return {Boolean} true or false if the file was successfully deleted143 */144 removeCacheFile: function () {145 return del(this._pathToFile);146 },147 /**148 * Destroy the file cache and cache content.149 * @method destroy150 */151 destroy: function () {152 const me = this;153 me._visited = {};154 me._persisted = {};155 156 me.removeCacheFile();157 },158};159 160module.exports = {161 /**162 * Alias for create. Should be considered depreacted. Will be removed in next releases163 *164 * @method load165 * @param docId {String} the id of the cache, would also be used as the name of the file cache166 * @param [cacheDir] {String} directory for the cache entry167 * @returns {cache} cache instance168 */169 load: function (docId, cacheDir) {170 return this.create(docId, cacheDir);171 },172 173 /**174 * Load a cache identified by the given Id. If the element does not exists, then initialize an empty175 * cache storage.176 *177 * @method create178 * @param docId {String} the id of the cache, would also be used as the name of the file cache179 * @param [cacheDir] {String} directory for the cache entry180 * @returns {cache} cache instance181 */182 create: function (docId, cacheDir) {183 const obj = Object.create(cache);184 obj.load(docId, cacheDir);185 return obj;186 },187 188 createFromFile: function (filePath) {189 const obj = Object.create(cache);190 obj.loadFile(filePath);191 return obj;192 },193 /**194 * Clear the cache identified by the given id. Caches stored in a different cache directory can be deleted directly195 *196 * @method clearCache197 * @param docId {String} the id of the cache, would also be used as the name of the file cache198 * @param cacheDir {String} the directory where the cache file was written199 * @returns {Boolean} true if the cache folder was deleted. False otherwise200 */201 clearCacheById: function (docId, cacheDir) {202 const filePath = cacheDir ? path.resolve(cacheDir, docId) : path.resolve(__dirname, '../.cache/', docId);203 return del(filePath);204 },205 /**206 * Remove all cache stored in the cache directory207 * @method clearAll208 * @returns {Boolean} true if the cache folder was deleted. False otherwise209 */210 clearAll: function (cacheDir) {211 const filePath = cacheDir ? path.resolve(cacheDir) : path.resolve(__dirname, '../.cache/');212 return del(filePath);213 },214};215 