alwaysai
Version:
The alwaysAI command-line interface (CLI)
46 lines • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ora = require("ora");
const fs_1 = require("fs");
const alwayscli_1 = require("@alwaysai/alwayscli");
const cloud_api_1 = require("@alwaysai/cloud-api");
const app_config_file_1 = require("../../../util/app-config-file");
const model_ids_cli_input_1 = require("../../../cli-inputs/model-ids-cli-input");
const rpc_client_1 = require("../../../rpc-client");
const echo_1 = require("../../../util/echo");
const download_model_version_package_1 = require("../../../model-manager/download-model-version-package");
const model_package_path_1 = require("../../../model-manager/model-package-path");
exports.addModelsAddCliLeaf = alwayscli_1.createLeaf({
name: 'add',
description: 'Add one or more alwaysAI models to this app',
args: model_ids_cli_input_1.modelIdsCliInput,
async action(modelIds) {
app_config_file_1.appConfigFile.read();
const rpcClient = await rpc_client_1.RpcClient();
const fetched = [];
for (const modelId of modelIds) {
const spinner = ora(`Fetch model "${modelId}"`).start();
try {
const { version } = await rpcClient.getModelVersion({ id: modelId });
if (!fs_1.existsSync(model_package_path_1.ModelPackagePath({ id: modelId, version }))) {
await download_model_version_package_1.downloadModelVersionPackage({ id: modelId, version });
}
fetched.push([modelId, version]);
spinner.succeed();
}
catch (ex) {
spinner.fail();
if (ex.code === cloud_api_1.ErrorCode.MODEL_VERSION_NOT_FOUND) {
throw new alwayscli_1.TerseError(`Model not found: "${modelId}"`);
}
throw ex;
}
}
fetched.forEach(([id, version]) => {
app_config_file_1.appConfigFile.addModel(id, version);
});
echo_1.echo();
echo_1.echo(app_config_file_1.appConfigFile.describeModels());
},
});
//# sourceMappingURL=add.js.map