inference-server
Version:
Libraries and server to build AI applications. Adapters to various native bindings allowing local inference. Integrate it with your application, or use as a microservice.
69 lines • 2.34 kB
JavaScript
import path from 'node:path';
import micromatch from 'micromatch';
import { indexModelCache } from '../cli/lib/indexModelCache.js';
import { loadConfig } from '../cli/lib/loadConfig.js';
import { getCacheDirPath } from '../lib/getCacheDirPath.js';
import { renderTreeView } from '../cli/lib/renderTreeView.js';
function matchCachedModels(cacheInfo, pattern) {
const matches = [];
const isMatch = micromatch.matcher(pattern);
const visit = (node, nodePath) => {
if (isMatch(nodePath)) {
matches.push(node);
}
if (node.type === 'directory') {
for (const child of node.children) {
visit(child, nodePath + '/' + child.name);
}
}
};
for (const node of cacheInfo.fileTree) {
visit(node, node.name);
}
return matches;
}
async function showModels(pattern) {
const config = await loadConfig();
let modelsCachePath = getCacheDirPath('models');
if (config?.options.cachePath) {
modelsCachePath = path.join(config.options.cachePath, 'models');
}
const cacheInfo = await indexModelCache(modelsCachePath, {
includeFiles: true,
includeUnused: true,
});
const models = matchCachedModels(cacheInfo, pattern);
if (models.length === 0) {
console.log('No models found matching the name');
return;
}
if (models.length > 1) {
console.log('Found multiple models matching the name:');
const treeLines = renderTreeView(models);
console.log(treeLines.join('\n'));
return;
}
const matchedModel = models[0];
const treeLines = renderTreeView([matchedModel]);
// console.debug(matchedModel)
// TODO: read metadata from gguf, onnx and safetensor files
console.log('Model files:');
console.log(treeLines.join('\n'));
}
export const showCommand = {
command: 'show <modelName>',
aliases: ['info', 'details'],
describe: 'Print details of a model',
builder: (yargs) => {
return yargs
.positional('modelName', {
type: 'string',
describe: 'Name of the model to show details for',
})
.demandOption('modelName');
},
handler: async (argv) => {
await showModels(argv.modelName);
},
};
//# sourceMappingURL=showCommand.js.map