Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit b385c72

Browse files
JSprumunozemilio
authored andcommitted
Add luis:train:run (#382)
* Add luis:train:run * Add flags typoe
1 parent ecbfe12 commit b385c72

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {expect, test} from '@oclif/test'
2+
const sinon = require('sinon')
3+
const uuidv1 = require('uuid/v1')
4+
const utils = require('../../../../src/utils/index')
5+
const fs = require('fs-extra')
6+
import * as rimraf from 'rimraf'
7+
8+
describe('luis:train:run', () => {
9+
10+
beforeEach(() => {
11+
sinon.stub(utils, 'processInputs').returnsArg(0)
12+
})
13+
14+
afterEach(() => {
15+
sinon.restore();
16+
});
17+
18+
test
19+
.stdout()
20+
.command(['luis:train:run', '--help'])
21+
.it('should print the help contents when --help is passed as an argument', ctx => {
22+
expect(ctx.stdout).to.contain('Issues asynchronous training request for LUIS application')
23+
})
24+
25+
test
26+
.stdout()
27+
.stderr()
28+
.command(['luis:train:run', '--appId', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--versionId', '0.1'])
29+
.it('displays an error if any required input parameters are missing', ctx => {
30+
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
31+
})
32+
33+
test
34+
.nock('https://westus.api.cognitive.microsoft.com', api => api
35+
.post(uri => uri.includes('train'))
36+
.reply(202, {"statusId": 2,"status": "UpToDate"})
37+
)
38+
.stdout()
39+
.command(['luis:train:run', '--appId', uuidv1(), '--versionId', '0.1', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com'])
40+
.it('issues an asynchronous training request', ctx => {
41+
expect(ctx.stdout).to.contain('Training request successfully issued')
42+
expect(ctx.stdout).to.contain('statusId')
43+
expect(ctx.stdout).to.contain('status')
44+
})
45+
46+
})

0 commit comments

Comments
 (0)