From 8ea67bbb3aec0ab2c6be093c844d0d12f003cfb7 Mon Sep 17 00:00:00 2001 From: Emilio Munoz Date: Wed, 10 Feb 2021 10:02:49 -0800 Subject: [PATCH 1/3] Adding mode flag to train command --- packages/luis/src/api/http-request.ts | 2 +- packages/luis/src/api/train.ts | 7 +++++-- packages/luis/src/commands/luis/train/run.ts | 5 +++-- packages/luis/test/commands/luis/train/run.test.ts | 11 +++++++++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/luis/src/api/http-request.ts b/packages/luis/src/api/http-request.ts index 0b6f5d142..43296cb6c 100644 --- a/packages/luis/src/api/http-request.ts +++ b/packages/luis/src/api/http-request.ts @@ -78,7 +78,7 @@ const httpRequest = async function (subscriptionKey: string, config: any) { if (error.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx - throw Error(error.response.statusText) + throw Error(`Code: ${error.response.statusText} Message: ${error.response.data.error.message}`) } else { // Something happened in setting up the request that triggered an Error throw Error(error.message) diff --git a/packages/luis/src/api/train.ts b/packages/luis/src/api/train.ts index fec819a36..bb9d1a21c 100644 --- a/packages/luis/src/api/train.ts +++ b/packages/luis/src/api/train.ts @@ -6,9 +6,12 @@ const urlPath = '/luis/authoring/v3.0-preview/apps' export default { async train( param: EndpointParameters, - versionId: string) { + versionId: string, + mode: string) { let url = buildUrl(param.endpoint) + `/${param.appId}/versions/${versionId}/train` - + if (mode) { + url += `?mode=${mode}` + } return http.post(url, param.subscriptionKey, {}) }, diff --git a/packages/luis/src/commands/luis/train/run.ts b/packages/luis/src/commands/luis/train/run.ts index 4f0eae986..27859f1fb 100644 --- a/packages/luis/src/commands/luis/train/run.ts +++ b/packages/luis/src/commands/luis/train/run.ts @@ -22,6 +22,7 @@ export default class LuisTrainRun extends Command { subscriptionKey: flags.string({description: '(required) LUIS cognitive services subscription key (default: config:LUIS:subscriptionKey)'}), appId: flags.string({description: '(required) LUIS application Id (defaults to config:LUIS:appId)'}), versionId: flags.string({description: '(required) Version to show training status (defaults to config:LUIS:versionId)'}), + mode: flags.string({description: 'Value specifying mode of training (Standard | Neural).'}), wait: flags.boolean({description: 'Wait until training complete and then display status'}), json: flags.boolean({description: 'Display output as JSON'}), } @@ -37,7 +38,7 @@ export default class LuisTrainRun extends Command { utils.validateRequiredProps(requiredProps) try { - const trainingRequestStatus = await Train.train({subscriptionKey, endpoint, appId}, versionId) + const trainingRequestStatus = await Train.train({subscriptionKey, endpoint, appId}, versionId, flags.mode) if (trainingRequestStatus) { await utils.writeToConsole(trainingRequestStatus) const output = flags.json ? JSON.stringify({Status: 'Success'}, null, 2) : '\nTraining request successfully issued' @@ -52,7 +53,7 @@ export default class LuisTrainRun extends Command { return this.checkTrainingStatus({subscriptionKey, endpoint, appId}, versionId, flags.json) } } catch (err) { - throw new CLIError(`Failed to issue training request: ${err}`) + throw new CLIError(`Failed to issue training request: ${err.message}`) } } diff --git a/packages/luis/test/commands/luis/train/run.test.ts b/packages/luis/test/commands/luis/train/run.test.ts index 93d70615e..0a6a8d1c3 100644 --- a/packages/luis/test/commands/luis/train/run.test.ts +++ b/packages/luis/test/commands/luis/train/run.test.ts @@ -53,4 +53,15 @@ describe('luis:train:run', () => { expect(ctx.stdout).to.contain('checking training status...') }) + test + .nock('https://westus.api.cognitive.microsoft.com', api => api + .post(uri => uri.includes('train?mode=Standard')) + .reply(202, {"statusId": 2,"status": "UpToDate"}) + ) + .stdout() + .command(['luis:train:run', '--appId', uuidv1(), '--versionId', '0.1', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--mode', 'Standard']) + .it('issues an asynchronous training request and reports when complete using trainning mode Standard', ctx => { + expect(ctx.stdout).to.contain('Training request successfully issued') + }) + }) From 91ee8e3910db62288fd7d0a988980d59d664f713 Mon Sep 17 00:00:00 2001 From: Emilio Munoz Date: Wed, 10 Feb 2021 10:38:19 -0800 Subject: [PATCH 2/3] Checking for error object --- packages/luis/src/api/http-request.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/luis/src/api/http-request.ts b/packages/luis/src/api/http-request.ts index 43296cb6c..42595d49b 100644 --- a/packages/luis/src/api/http-request.ts +++ b/packages/luis/src/api/http-request.ts @@ -78,7 +78,12 @@ const httpRequest = async function (subscriptionKey: string, config: any) { if (error.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx - throw Error(`Code: ${error.response.statusText} Message: ${error.response.data.error.message}`) + let message = '' + if(error.response.data + && error.response.data.error) { + message = error.response.data.error.message + } + throw Error(`Code: ${error.response.statusText} ${message}`) } else { // Something happened in setting up the request that triggered an Error throw Error(error.message) From 5e214cde58649f71227e5e5031bea02c4c95d498 Mon Sep 17 00:00:00 2001 From: Emilio Munoz Date: Wed, 10 Feb 2021 11:13:05 -0800 Subject: [PATCH 3/3] Applying PR feedback --- packages/luis/src/api/http-request.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/luis/src/api/http-request.ts b/packages/luis/src/api/http-request.ts index 42595d49b..b86520b0c 100644 --- a/packages/luis/src/api/http-request.ts +++ b/packages/luis/src/api/http-request.ts @@ -78,11 +78,7 @@ const httpRequest = async function (subscriptionKey: string, config: any) { if (error.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx - let message = '' - if(error.response.data - && error.response.data.error) { - message = error.response.data.error.message - } + let message = error?.response?.data?.error?.message ?? '' throw Error(`Code: ${error.response.statusText} ${message}`) } else { // Something happened in setting up the request that triggered an Error