bootstrap

This commit is contained in:
Ryan Huang
2024-04-25 13:15:24 -04:00
parent d5c2b364d0
commit d66e336ce0
5 changed files with 50 additions and 31 deletions

View File

@ -15,6 +15,7 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@lmstudio/lms-common": "^0.5.1", "@lmstudio/lms-common": "^0.5.1",
"@lmstudio/lms-lmstudio": "^0.0.3",
"@lmstudio/sdk": "^0.0.4", "@lmstudio/sdk": "^0.0.4",
"boxen": "^5.1.2", "boxen": "^5.1.2",
"chalk": "^4.1.2", "chalk": "^4.1.2",

View File

@ -1,4 +1,5 @@
import { run, subcommands } from "cmd-ts"; import { run, subcommands } from "cmd-ts";
import { bootstrap } from "./subcommands/bootstrap";
import { create } from "./subcommands/create"; import { create } from "./subcommands/create";
import { ls, ps } from "./subcommands/list"; import { ls, ps } from "./subcommands/list";
import { load } from "./subcommands/load"; import { load } from "./subcommands/load";
@ -24,6 +25,7 @@ const cli = subcommands({
unload, unload,
create, create,
version, version,
bootstrap,
}, },
}); });

View File

@ -0,0 +1,11 @@
import { installCli } from "@lmstudio/lms-lmstudio/dist/installCli";
import { command } from "cmd-ts";
export const bootstrap = command({
name: "bootstrap",
description: "Bootstrap the CLI",
args: {},
handler: async () => {
await installCli({ skipConfirmation: true });
},
});

View File

@ -140,14 +140,14 @@ function printDownloadedModelsTable(
if (models.length === 1) { if (models.length === 1) {
const model = models[0]; const model = models[0];
return { return {
path: group, path: chalk.cyanBright(group),
sizeBytes: formatSizeBytes1000(model.sizeBytes), sizeBytes: chalk.cyanBright(formatSizeBytes1000(model.sizeBytes)),
arch: architecture(model.architecture), arch: chalk.cyanBright(architecture(model.architecture)),
loaded: loadedCheck(model.loadedIdentifiers.length), loaded: loadedCheck(model.loadedIdentifiers.length),
}; };
} else { } else {
return { return {
path: group, path: chalk.cyanBright(group),
arch: chalk.gray(`(...${models.length} options)`), arch: chalk.gray(`(...${models.length} options)`),
loaded: loadedCheck( loaded: loadedCheck(
models.reduce((acc, model) => acc + model.loadedIdentifiers.length, 0), models.reduce((acc, model) => acc + model.loadedIdentifiers.length, 0),
@ -166,14 +166,14 @@ function printDownloadedModelsTable(
align: "left", align: "left",
}, },
path: { path: {
headingTransform: () => chalk.greenBright(title), headingTransform: () => chalk(title),
}, },
sizeBytes: { sizeBytes: {
headingTransform: () => chalk.greenBright("SIZE"), headingTransform: () => chalk("SIZE"),
align: "right", align: "right",
}, },
arch: { arch: {
headingTransform: () => chalk.greenBright("ARCHITECTURE"), headingTransform: () => chalk("ARCHITECTURE"),
align: "center", align: "center",
}, },
}, },

View File

@ -168,30 +168,7 @@ export const load = command({
logger.debug("Initial filtered models length:", initialFilteredModels.length); logger.debug("Initial filtered models length:", initialFilteredModels.length);
let model: DownloadedModel; let model: DownloadedModel;
if (initialFilteredModels.length !== 1 && !yes) { if (yes) {
if (path === undefined) {
console.info();
model = await selectModelToLoad(models, modelPaths, "", 4, lastLoadedMap);
} else if (initialFilteredModels.length === 0) {
console.info();
console.info(
chalk.redBright(text`
! Cannot find a model matching the provided path (${chalk.yellowBright(path)}). Please
select one from the list below.
`),
);
path = "";
model = await selectModelToLoad(models, modelPaths, path, 5, lastLoadedMap);
} else {
console.info();
console.info(
text`
! Multiple models match the provided path. Please select one.
`,
);
model = await selectModelToLoad(models, modelPaths, path ?? "", 5, lastLoadedMap);
}
} else {
if (initialFilteredModels.length === 0) { if (initialFilteredModels.length === 0) {
logger.errorWithoutPrefix( logger.errorWithoutPrefix(
makeTitledPrettyError( makeTitledPrettyError(
@ -212,6 +189,34 @@ export const load = command({
process.exit(1); process.exit(1);
} }
model = models[initialFilteredModels[0].index]; model = models[initialFilteredModels[0].index];
} else {
console.info();
if (path === undefined) {
model = await selectModelToLoad(models, modelPaths, "", 4, lastLoadedMap);
} else if (initialFilteredModels.length === 0) {
console.info(
chalk.redBright(text`
! Cannot find a model matching the provided path (${chalk.yellowBright(path)}). Please
select one from the list below.
`),
);
path = "";
model = await selectModelToLoad(models, modelPaths, path, 5, lastLoadedMap);
} else if (initialFilteredModels.length === 1) {
console.info(
text`
! Confirm model selection, or select a different model.
`,
);
model = await selectModelToLoad(models, modelPaths, path ?? "", 5, lastLoadedMap);
} else {
console.info(
text`
! Multiple models match the provided path. Please select one.
`,
);
model = await selectModelToLoad(models, modelPaths, path ?? "", 5, lastLoadedMap);
}
} }
const modelInLastLoadedModelsIndex = lastLoadedModels.indexOf(model.path); const modelInLastLoadedModelsIndex = lastLoadedModels.indexOf(model.path);