@@ -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