UNPKG

alwaysai

Version:

The alwaysAI command-line interface (CLI)

48 lines 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ora = require("ora"); const logSymbols = require("log-symbols"); 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 rpc_client_1 = require("../../../rpc-client"); const echo_1 = require("../../../util/echo"); exports.appModelsUpdate = alwayscli_1.createLeaf({ name: 'update', description: "Update this application's models to the latest versions", async action() { const { models } = app_config_file_1.appConfigFile.read(); const rpcClient = await rpc_client_1.RpcClient(); const updates = []; if (!models || Object.keys(models).length === 0) { return 'No models to update!'; } const spinner = ora('Fetching model metadata').start(); for (const [id, currentVersion] of Object.entries(models)) { try { const { version: latestVersion } = await rpcClient.getModelVersion({ id }); if (currentVersion !== latestVersion) { updates.push([id, currentVersion, latestVersion]); } } catch (ex) { spinner.fail(); if (ex.code === cloud_api_1.ErrorCode.MODEL_VERSION_NOT_FOUND) { throw new alwayscli_1.TerseError(`Model not found: "${id}"`); } throw ex; } } spinner.succeed(); if (updates.length === 0) { return `${logSymbols.success} All models are already up to date!`; } echo_1.echo(`${logSymbols.success} Updated models`); updates.forEach(([id, currentVersion, nextVersion]) => { echo_1.echo(` ${id} ${currentVersion} --> ${nextVersion}`); app_config_file_1.appConfigFile.addModel(id, nextVersion); }); return undefined; }, }); //# sourceMappingURL=update.js.map