alwaysai
Version:
The alwaysAI command-line interface (CLI)
61 lines • 2.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.testSuiteFuncs = exports.modelPrune = void 0;
const path = require("path");
const rimraf = require("rimraf");
const logSymbols = require("log-symbols");
const alwayscli_1 = require("@alwaysai/alwayscli");
const util_1 = require("../../util");
const model_1 = require("../../core/model");
const fs_1 = require("fs");
function removeCache(modelPath, ignore) {
let glob = '*';
if (ignore) {
glob = ignore.join('|');
glob = `!(${glob})*`;
}
const removePath = path.join(modelPath, glob);
util_1.logger.debug(removePath);
rimraf.sync(removePath);
}
function errorIfIdNotInCache(modelPath, id) {
if (!(0, fs_1.existsSync)(modelPath)) {
throw new alwayscli_1.CliTerseError(`Model ${id} not found in cache`);
}
}
function errorIfIgnoredNotInCache(ignoreVersions, modelPath, id) {
ignoreVersions.forEach((version) => {
if (!(0, fs_1.existsSync)(path.join(modelPath, `${version}.tar.gz`))) {
throw new alwayscli_1.CliTerseError(`Ignore version ${version} for model ${id} not found in cache.`);
}
});
}
exports.modelPrune = (0, alwayscli_1.CliLeaf)({
name: 'prune',
description: 'Prune model from your model cache',
positionalInput: (0, alwayscli_1.CliStringInput)({
placeholder: 'Model id ex: alwaysai/human-pose',
required: true
}),
namedInputs: {
ignore: (0, alwayscli_1.CliStringArrayInput)({
description: 'Versions to ignore ex: 0.4 0.2'
})
},
async action(id, opts) {
const modelPath = path.join((0, model_1.ModelPackageDirectory)(), id);
errorIfIdNotInCache(modelPath, id);
const ignoreVersions = opts['ignore'];
if (ignoreVersions) {
errorIfIgnoredNotInCache(ignoreVersions, modelPath, id);
}
removeCache(path.join((0, model_1.ModelPackageDirectory)(), id), ignoreVersions);
(0, util_1.echo)(`${logSymbols.success} Pruned ${id} from model cache`);
}
});
exports.testSuiteFuncs = {
errorIfIdNotInCache,
errorIfIgnoredNotInCache,
removeCache
};
//# sourceMappingURL=prune.js.map