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

Commit d80ed6a

Browse files
authored
Adding mode flag to train command (#1113)
* Adding mode flag to train command * Checking for error object * Applying PR feedback
1 parent dbba6c6 commit d80ed6a

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

packages/luis/src/api/http-request.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ const httpRequest = async function (subscriptionKey: string, config: any) {
7878
if (error.response) {
7979
// The request was made and the server responded with a status code
8080
// that falls out of the range of 2xx
81-
throw Error(error.response.statusText)
81+
let message = error?.response?.data?.error?.message ?? ''
82+
throw Error(`Code: ${error.response.statusText} ${message}`)
8283
} else {
8384
// Something happened in setting up the request that triggered an Error
8485
throw Error(error.message)

packages/luis/src/api/train.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ const urlPath = '/luis/authoring/v3.0-preview/apps'
66
export default {
77
async train(
88
param: EndpointParameters,
9-
versionId: string) {
9+
versionId: string,
10+
mode: string) {
1011
let url = buildUrl(param.endpoint) + `/${param.appId}/versions/${versionId}/train`
11-
12+
if (mode) {
13+
url += `?mode=${mode}`
14+
}
1215
return http.post(url, param.subscriptionKey, {})
1316
},
1417

packages/luis/src/commands/luis/train/run.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default class LuisTrainRun extends Command {
2222
subscriptionKey: flags.string({description: '(required) LUIS cognitive services subscription key (default: config:LUIS:subscriptionKey)'}),
2323
appId: flags.string({description: '(required) LUIS application Id (defaults to config:LUIS:appId)'}),
2424
versionId: flags.string({description: '(required) Version to show training status (defaults to config:LUIS:versionId)'}),
25+
mode: flags.string({description: 'Value specifying mode of training (Standard | Neural).'}),
2526
wait: flags.boolean({description: 'Wait until training complete and then display status'}),
2627
json: flags.boolean({description: 'Display output as JSON'}),
2728
}
@@ -37,7 +38,7 @@ export default class LuisTrainRun extends Command {
3738
utils.validateRequiredProps(requiredProps)
3839

3940
try {
40-
const trainingRequestStatus = await Train.train({subscriptionKey, endpoint, appId}, versionId)
41+
const trainingRequestStatus = await Train.train({subscriptionKey, endpoint, appId}, versionId, flags.mode)
4142
if (trainingRequestStatus) {
4243
await utils.writeToConsole(trainingRequestStatus)
4344
const output = flags.json ? JSON.stringify({Status: 'Success'}, null, 2) : '\nTraining request successfully issued'
@@ -52,7 +53,7 @@ export default class LuisTrainRun extends Command {
5253
return this.checkTrainingStatus({subscriptionKey, endpoint, appId}, versionId, flags.json)
5354
}
5455
} catch (err) {
55-
throw new CLIError(`Failed to issue training request: ${err}`)
56+
throw new CLIError(`Failed to issue training request: ${err.message}`)
5657
}
5758
}
5859

packages/luis/test/commands/luis/train/run.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,15 @@ describe('luis:train:run', () => {
5353
expect(ctx.stdout).to.contain('checking training status...')
5454
})
5555

56+
test
57+
.nock('https://westus.api.cognitive.microsoft.com', api => api
58+
.post(uri => uri.includes('train?mode=Standard'))
59+
.reply(202, {"statusId": 2,"status": "UpToDate"})
60+
)
61+
.stdout()
62+
.command(['luis:train:run', '--appId', uuidv1(), '--versionId', '0.1', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--mode', 'Standard'])
63+
.it('issues an asynchronous training request and reports when complete using trainning mode Standard', ctx => {
64+
expect(ctx.stdout).to.contain('Training request successfully issued')
65+
})
66+
5667
})

0 commit comments

Comments
 (0)