import chalk from 'chalk'; import clear from 'clear'; import figlet from 'figlet'; import { ICli, ICliRoutes } from "../types"; import Config from '../config'; import { displayStepper } from '../helpers'; import { InquirerService, ModelService } from '../services'; import { ProjectsCli } from '../cli'; class DeployService implements ICli { public routes: ICliRoutes[] = []; constructor() { this.routes.push({ command: 'models', description: 'Deploy ML model', subCommands: [ { command: 'deploy', description: 'Deploy Ml models', handler: this.deployModel, options: [ { flags: '-m, --model_id ', description: 'Model id', }, { flags: '-p, --project_id ', description: 'Project id', }, { flags: '-i, --interactive', description: 'Enable interactive mode', } ] }, { command: 'list', description: 'List all the models of projects', handler: this.listModels, options: [ { flags: '-p, --project_id ', description: 'Project id', }, { flags: '-i, --interactive', description: 'Select models from list of projects', } ] }, { command: 'create', description: 'Create ml model', handler: this.createModel, options: [ { flags: '-c, --cpu ', defaultValue: '1', description: 'Cpu for the model', }, { flags: '-m, --model_name ', description: 'Name of the model', }, { flags: '-r, --ram ', description: 'RAM for the model', defaultValue: '1', }, { flags: '-p, --project_id ', description: 'Project id', }, { flags: '-i, --interactive', description: 'Create model by selecting projects', } ] } ] }); } public deployModel = async () => { this.displayHeading(0); console.log('Model Deployed'); } public listModels = async (options) => { if (options.interactive) { return this.interactiveListModels(); } if (!options.project_id) { options.project_id = await ProjectsCli.selectProjectInteractive(); } const models = await ModelService.listModels(options.project_id); console.log(models); } public createModel = async (options) => { if (options.interactive) { return this.interactiveCreateModel(); } if (!options.project_id) { options.project_id = await ProjectsCli.selectProjectInteractive(); if (!options.project_id) { return; } } if (!options.model_name) { options.model_name = await InquirerService.takeInput('Enter model name : '); } if (!/[0-9]+$/g.test(options.ram)) { console.log('Ram should be numeric value') options.ram = await InquirerService.takeInput('Enter ram : ', 'number'); } if (!/[0-9]+$/g.test(options.cpu)) { console.log('CPU should be numeric value') options.cpu = await InquirerService.takeInput('Enter number of CPU\'s : ', 'number'); } await ModelService.createModel({ cpu: Number(options.cpu), name: options.model_name, projectId: options.project_id, ram: Number(options.ram) }); console.log('Model has been created...'); console.log(`Run this command to see all models "${Config.PROJECT_NAME} models list --project_id ${options.project_id}"`) } private async interactiveCreateModel() { const projectId = await ProjectsCli.selectProjectInteractive(); if (!projectId) { return; } const name = await InquirerService.takeInput('Enter model name : '); const cpu = await InquirerService.takeInput('Enter number of CPU\'s : ', 'number'); const ram = await InquirerService.takeInput('Enter ram : ', 'number'); await ModelService.createModel({ cpu: Number(cpu), name, projectId, ram: Number(ram) }); console.log('Model has been created...'); console.log(`Run this command to see all models "${Config.PROJECT_NAME} models list --project_id ${projectId}"`) } private async interactiveListModels() { const projectId = await ProjectsCli.selectProjectInteractive(); if (!projectId) { return; } const models = await ModelService.listModels(projectId); console.log(models); } private displayHeading(active: number) { clear(); console.log(chalk.red(figlet.textSync(Config.PROJECT_NAME, { horizontalLayout: 'full', }))); console.log('Deploy your machine learning model in 4 easy steps !!!\n'); displayStepper(['Login', 'Project', 'Path', 'Done'], active); } } export default new DeployService();