|
| 1 | +/*! |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. |
| 4 | + */ |
| 5 | + |
| 6 | +import {CLIError, Command, flags} from '@microsoft/bf-cli-command' |
| 7 | + |
| 8 | +const utils = require('../../../utils/index') |
| 9 | + |
| 10 | +export default class LuisTrainRun extends Command { |
| 11 | + static description = 'Issues asynchronous training request for LUIS application' |
| 12 | + |
| 13 | + static examples = [` |
| 14 | + $ bf luis:train:run --appId {APPLICATION_ID} --versionId {VERSION_ID} --endpoint {ENDPOINT} --subscriptionKey {SUBSCRIPTION_KEY} |
| 15 | + `] |
| 16 | + |
| 17 | + static flags: any = { |
| 18 | + help: flags.help({char: 'h'}), |
| 19 | + endpoint: flags.string({description: 'LUIS endpoint hostname'}), |
| 20 | + subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (mandatory, default: config:LUIS:subscriptionKey)'}), |
| 21 | + appId: flags.string({description: 'LUIS application Id (mandatory, defaults to config:LUIS:appId)'}), |
| 22 | + versionId: flags.string({description: 'Version to show training status (mandatory, defaults to config:LUIS:versionId)'}), |
| 23 | + } |
| 24 | + |
| 25 | + async run() { |
| 26 | + const {flags} = this.parse(LuisTrainRun) |
| 27 | + const flagLabels = Object.keys(LuisTrainRun.flags) |
| 28 | + const configDir = this.config.configDir |
| 29 | + |
| 30 | + let {endpoint, subscriptionKey, appId, versionId} = await utils.processInputs(flags, flagLabels, configDir) |
| 31 | + |
| 32 | + const requiredProps = {endpoint, subscriptionKey, appId, versionId} |
| 33 | + utils.validateRequiredProps(requiredProps) |
| 34 | + |
| 35 | + const client = utils.getLUISClient(subscriptionKey, endpoint) |
| 36 | + |
| 37 | + try { |
| 38 | + const trainingRequestStatus = await client.train.trainVersion(appId, versionId) |
| 39 | + if (trainingRequestStatus) { |
| 40 | + await utils.writeToConsole(trainingRequestStatus) |
| 41 | + this.log('\nTraining request successfully issued') |
| 42 | + } |
| 43 | + } catch (err) { |
| 44 | + throw new CLIError(`Failed to issue training request: ${err}`) |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | +} |
0 commit comments