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

Commit c622c6f

Browse files
authored
enable luis vnext train mode (#1099)
1 parent b2ce5f5 commit c622c6f

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

packages/lu/src/parser/lubuild/builder.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ export class Builder {
201201
// default to false
202202
let directVersionPublish = options.directVersionPublish || false
203203

204+
// set train mode
205+
let trainMode = options.trainMode
206+
204207
// settings assets like app id and version returned from luis api call
205208
let settingsAssets: any[] = []
206209

@@ -257,7 +260,7 @@ export class Builder {
257260

258261
if (needTrainAndPublish) {
259262
// train and publish application
260-
await this.trainAndPublishApplication(luBuildCore, recognizer, timeBucketOfRequests, isStaging, directVersionPublish)
263+
await this.trainAndPublishApplication(luBuildCore, recognizer, timeBucketOfRequests, isStaging, directVersionPublish, trainMode)
261264
}
262265

263266
// init settings asset
@@ -425,11 +428,11 @@ export class Builder {
425428
return true
426429
}
427430

428-
async trainAndPublishApplication(luBuildCore: LuBuildCore, recognizer: Recognizer, timeBucket: number, isStaging: boolean, directVersionPublish: boolean) {
431+
async trainAndPublishApplication(luBuildCore: LuBuildCore, recognizer: Recognizer, timeBucket: number, isStaging: boolean, directVersionPublish: boolean, trainMode: string) {
429432
// send train application request
430433
this.handler(`${recognizer.getLuPath()} training version=${recognizer.versionId}\n`)
431434
await delay(timeBucket)
432-
await luBuildCore.trainApplication(recognizer.getAppId(), recognizer.versionId)
435+
await luBuildCore.trainApplication(recognizer.getAppId(), recognizer.versionId, trainMode)
433436
this.handler(`${recognizer.getLuPath()} waiting for training for version=${recognizer.versionId}...\n`)
434437
let done = true
435438
do {

packages/lu/src/parser/lubuild/core.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class LuBuildCore {
2222
private readonly retryCount: number
2323
private readonly retryDuration: number
2424
private readonly headers: any
25+
private readonly trainMode: string | undefined
2526

2627
constructor(subscriptionKey: string, endpoint: string, retryCount: number, retryDuration: number) {
2728
this.subscriptionKey = subscriptionKey
@@ -37,6 +38,9 @@ export class LuBuildCore {
3738
// set user agent
3839
const luisUserAgent = process.env['LUIS_USER_AGENT'] || this.getUserAgent()
3940

41+
// set luis train mode
42+
this.trainMode = process.env['LUIS_TRAIN_MODE']
43+
4044
// set headers
4145
this.headers = {
4246
'Content-Type': 'application/json',
@@ -299,19 +303,24 @@ export class LuBuildCore {
299303
}
300304
}
301305

302-
public async trainApplication(appId: string, versionId: string) {
306+
public async trainApplication(appId: string, versionId: string, trainMode: string) {
307+
let mode = trainMode || this.trainMode
308+
let url = `${this.endpoint}/luis/authoring/v3.0-preview/apps/${appId}/versions/${versionId}/train`
309+
url += mode ? `?mode=${mode}` : ''
310+
311+
let messageData
303312
let retryCount = this.retryCount + 1
304-
let error
313+
let error: any
305314
while (retryCount > 0) {
306-
if (error === undefined || error.statusCode === rateLimitErrorCode) {
307-
try {
308-
await this.client.train.trainVersion(appId, versionId)
309-
break
310-
} catch (e) {
311-
error = e
312-
retryCount--
313-
if (retryCount > 0) await delay(this.retryDuration)
314-
}
315+
if (error === undefined || error.code === rateLimitErrorCode.toString()) {
316+
let response = await fetch(url, {method: 'POST', headers: this.headers})
317+
messageData = await response.json()
318+
319+
if (messageData.error === undefined) break
320+
321+
error = messageData.error
322+
retryCount--
323+
if (retryCount > 0) await delay(this.retryDuration)
315324
} else {
316325
throw error
317326
}
@@ -320,6 +329,8 @@ export class LuBuildCore {
320329
if (retryCount === 0) {
321330
throw error
322331
}
332+
333+
return messageData
323334
}
324335

325336
public async getTrainingStatus(appId: string, versionId: string) {

0 commit comments

Comments
 (0)