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

Commit c063415

Browse files
authored
add version in luis recognizer and settings file and adjust deleteOldVersion interface (#962)
* add version support * adjust removeOldVersions to keepVersions * fix naming
1 parent ed789e7 commit c063415

File tree

22 files changed

+141
-34
lines changed

22 files changed

+141
-34
lines changed

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const LUOptions = require('./../lu/luOptions')
2222
const Content = require('./../lu/lu')
2323
const recognizerType = require('./../utils/enums/recognizertypes')
2424

25+
const maxVersionCount = 100
26+
2527
export class Builder {
2628
private readonly handler: (input: string) => any
2729

@@ -159,7 +161,7 @@ export class Builder {
159161
botName: string,
160162
suffix: string,
161163
fallbackLocale: string,
162-
deleteOldVersion: boolean,
164+
keptVersionCount: number,
163165
isStaging: boolean,
164166
multiRecognizers?: Map<string, MultiLanguageRecognizer>,
165167
settings?: Settings,
@@ -227,7 +229,7 @@ export class Builder {
227229
// otherwise create a new application
228230
if (recognizer.getAppId() && recognizer.getAppId() !== '') {
229231
// To see if need update the model
230-
needTrainAndPublish = await this.updateApplication(currentApp, luBuildCore, recognizer, timeBucket, deleteOldVersion)
232+
needTrainAndPublish = await this.updateApplication(currentApp, luBuildCore, recognizer, timeBucket, keptVersionCount ?? maxVersionCount)
231233
} else {
232234
// create a new application
233235
needTrainAndPublish = await this.createApplication(currentApp, luBuildCore, recognizer, timeBucket)
@@ -256,7 +258,10 @@ export class Builder {
256258

257259
// update settings asset
258260
if (settings) {
259-
settings.luis[content.name.split('.').join('_').replace(/-/g, '_')] = recognizer.getAppId()
261+
settings.luis[content.name.split('.').join('_').replace(/-/g, '_')] = {
262+
"appId": recognizer.getAppId(),
263+
"version": recognizer.versionId
264+
}
260265
}
261266
}))
262267
}
@@ -367,7 +372,7 @@ export class Builder {
367372
return currentApp
368373
}
369374

370-
async updateApplication(currentApp: any, luBuildCore: LuBuildCore, recognizer: Recognizer, timeBucket: number, deleteOldVersion: boolean) {
375+
async updateApplication(currentApp: any, luBuildCore: LuBuildCore, recognizer: Recognizer, timeBucket: number, keptVersionCount: number) {
371376
await delay(timeBucket)
372377
const appInfo = await luBuildCore.getApplicationInfo(recognizer.getAppId())
373378
recognizer.versionId = appInfo.activeVersion || appInfo.endpoints.PRODUCTION.versionId
@@ -387,11 +392,13 @@ export class Builder {
387392
this.handler(`${recognizer.getLuPath()} creating version=${newVersionId}\n`)
388393
await delay(timeBucket)
389394
await luBuildCore.importNewVersion(recognizer.getAppId(), currentApp, options)
390-
391-
if (deleteOldVersion) {
392-
await delay(timeBucket)
393-
const versionObjs = await luBuildCore.listApplicationVersions(recognizer.getAppId())
394-
for (const versionObj of versionObjs) {
395+
396+
// get all available versions
397+
await delay(timeBucket)
398+
const versionObjs = await luBuildCore.listApplicationVersions(recognizer.getAppId())
399+
if (keptVersionCount < versionObjs.length) {
400+
const versionObjsToDelete = versionObjs.reverse().splice(0, versionObjs.length - keptVersionCount)
401+
for (const versionObj of versionObjsToDelete) {
395402
if (versionObj.version !== newVersionId) {
396403
this.handler(`${recognizer.getLuPath()} deleting old version=${versionObj.version}`)
397404
await delay(timeBucket)
@@ -479,7 +486,10 @@ export class Builder {
479486
for (const content of contents) {
480487
const luisAppsMap = JSON.parse(content.content).luis
481488
for (const appName of Object.keys(luisAppsMap)) {
482-
settings.luis[appName] = luisAppsMap[appName]
489+
settings.luis[appName] = {
490+
"appId": luisAppsMap[appName]["appId"],
491+
"version": luisAppsMap[appName]["version"]
492+
}
483493
}
484494
}
485495

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class Recognizer {
2626
versionId: string
2727
private readonly id: string
2828
private readonly applicationId: string | undefined
29+
private readonly version: string | undefined
2930
private readonly endpoint: string | undefined
3031
private readonly endpointKey: string | undefined
3132
private readonly $schema: string | undefined
@@ -35,10 +36,11 @@ export class Recognizer {
3536
constructor(private readonly luFile: string, targetFileName: string, schema?: string) {
3637
this.appId = ''
3738
this.id = `LUIS_${targetFileName.split('.')[0]}`
38-
this.applicationId = `=settings.luis.${targetFileName.split('.').join('_').replace(/-/g, '_')}`
39+
this.applicationId = `=settings.luis.${targetFileName.split('.').join('_').replace(/-/g, '_')}.appId`
3940
this.endpoint = '=settings.luis.endpoint'
4041
this.endpointKey = '=settings.luis.endpointKey'
41-
this.versionId = '0.1'
42+
this.version = `=settings.luis.${targetFileName.split('.').join('_').replace(/-/g, '_')}.version`
43+
this.versionId = "0.1"
4244
this.$schema = schema
4345
}
4446

@@ -47,6 +49,7 @@ export class Recognizer {
4749
$kind: 'Microsoft.LuisRecognizer',
4850
id: this.id,
4951
applicationId: this.applicationId,
52+
version: this.version,
5053
endpoint: this.endpoint,
5154
endpointKey: this.endpointKey
5255
}

packages/luis/src/commands/luis/build.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ export default class LuisBuild extends Command {
145145

146146
// update or create and then train and publish luis applications based on loaded resources
147147
if (log) this.log('Handling applications...')
148-
const dialogContents = await builder.build(luContents, recognizers, authoringKey, endpoint, botName, suffix, fallbackLocale, deleteOldVersion, isStaging, multiRecognizers, settings, crosstrainedRecognizers, dialog)
148+
149+
// LUIS support maximun 100 versions for an application, keepVersions default set to 100 if deleteOldVersion is not specified.
150+
let keptVersionCount = 100
151+
if (deleteOldVersion) keptVersionCount = 1
152+
153+
const dialogContents = await builder.build(luContents, recognizers, authoringKey, endpoint, botName, suffix, fallbackLocale, keptVersionCount, isStaging, multiRecognizers, settings, crosstrainedRecognizers, dialog)
149154

150155
// write dialog assets based on config
151156
if (out) {

packages/luis/test/commands/luis/build.test.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ describe('luis:build update application succeed when utterances changed', () =>
152152
.post(uri => uri.includes('import'))
153153
.reply(201, '0.2')
154154

155+
nock('https://westus.api.cognitive.microsoft.com')
156+
.get(uri => uri.includes('apps'))
157+
.reply(200, [
158+
{
159+
version: '0.2'
160+
},
161+
{
162+
version: '0.1'
163+
}])
164+
155165
nock('https://westus.api.cognitive.microsoft.com')
156166
.post(uri => uri.includes('train'))
157167
.reply(202, {
@@ -216,6 +226,16 @@ describe('luis:build update application succeed when utterances added', () => {
216226
nock('https://westus.api.cognitive.microsoft.com')
217227
.post(uri => uri.includes('import'))
218228
.reply(201, '0.2')
229+
230+
nock('https://westus.api.cognitive.microsoft.com')
231+
.get(uri => uri.includes('apps'))
232+
.reply(200, [
233+
{
234+
version: '0.2'
235+
},
236+
{
237+
version: '0.1'
238+
}])
219239

220240
nock('https://westus.api.cognitive.microsoft.com')
221241
.post(uri => uri.includes('train'))
@@ -704,15 +724,29 @@ describe('luis:build update application succeed with parameters set from luconfi
704724
.get(uri => uri.includes('apps'))
705725
.reply(200, [
706726
{
707-
version: '0.1'
727+
version: '0.4'
728+
},
729+
{
730+
version: '0.3'
708731
},
709732
{
710733
version: '0.2'
734+
},
735+
{
736+
version: '0.1'
711737
}
712738
])
713739

714740
nock('https://chinaeast2.api.cognitive.azure.cn')
715-
.delete(uri => uri.includes('apps'))
741+
.delete(uri => uri.includes('0.1'))
742+
.reply(200)
743+
744+
nock('https://chinaeast2.api.cognitive.azure.cn')
745+
.delete(uri => uri.includes('0.2'))
746+
.reply(200)
747+
748+
nock('https://chinaeast2.api.cognitive.azure.cn')
749+
.delete(uri => uri.includes('0.3'))
716750
.reply(200)
717751

718752
nock('https://chinaeast2.api.cognitive.azure.cn')
@@ -849,6 +883,16 @@ describe('luis:build update application succeed when activeVersion is null', ()
849883
.post(uri => uri.includes('import'))
850884
.reply(201, '0.2')
851885

886+
nock('https://westus.api.cognitive.microsoft.com')
887+
.get(uri => uri.includes('apps'))
888+
.reply(200, [
889+
{
890+
version: '0.2'
891+
},
892+
{
893+
version: '0.1'
894+
}])
895+
852896
nock('https://westus.api.cognitive.microsoft.com')
853897
.post(uri => uri.includes('train'))
854898
.reply(202, {
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"luis": {
3-
"non_empty_en_us_lu": "f8c64e2a-1111-3a09-8f78-39d7adc76ec5"
3+
"non_empty_en_us_lu": {
4+
"appId": "f8c64e2a-1111-3a09-8f78-39d7adc76ec5",
5+
"version": "0.1"
6+
}
47
}
58
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"$kind": "Microsoft.LuisRecognizer",
33
"id": "LUIS_non-empty",
4-
"applicationId": "=settings.luis.non_empty_en_us_lu",
4+
"applicationId": "=settings.luis.non_empty_en_us_lu.appId",
5+
"version": "=settings.luis.non_empty_en_us_lu.version",
56
"endpoint": "=settings.luis.endpoint",
67
"endpointKey": "=settings.luis.endpointKey"
78
}
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
{
22
"luis": {
3-
"foo_fr_fr_lu": "f8c64e2a-1111-3a09-8f78-39d7adc76ec5",
4-
"foo_en_us_lu": "f8c64e2a-2222-3a09-8f78-39d7adc76ec5",
5-
"foo_zh_cn_lu": "f8c64e2a-3333-3a09-8f78-39d7adc76ec5"
3+
"foo_fr_fr_lu": {
4+
"appId": "f8c64e2a-1111-3a09-8f78-39d7adc76ec5",
5+
"version": "0.1"
6+
},
7+
"foo_en_us_lu": {
8+
"appId": "f8c64e2a-2222-3a09-8f78-39d7adc76ec5",
9+
"version": "0.1"
10+
},
11+
"foo_zh_cn_lu": {
12+
"appId": "f8c64e2a-3333-3a09-8f78-39d7adc76ec5",
13+
"version": "0.1"
14+
}
615
}
716
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"$kind": "Microsoft.LuisRecognizer",
33
"id": "LUIS_foo",
4-
"applicationId": "=settings.luis.foo_en_us_lu",
4+
"applicationId": "=settings.luis.foo_en_us_lu.appId",
5+
"version": "=settings.luis.foo_en_us_lu.version",
56
"endpoint": "=settings.luis.endpoint",
67
"endpointKey": "=settings.luis.endpointKey"
78
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"$kind": "Microsoft.LuisRecognizer",
33
"id": "LUIS_foo",
4-
"applicationId": "=settings.luis.foo_fr_fr_lu",
4+
"applicationId": "=settings.luis.foo_fr_fr_lu.appId",
5+
"version": "=settings.luis.foo_fr_fr_lu.version",
56
"endpoint": "=settings.luis.endpoint",
67
"endpointKey": "=settings.luis.endpointKey"
78
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"$kind": "Microsoft.LuisRecognizer",
33
"id": "LUIS_foo",
4-
"applicationId": "=settings.luis.foo_zh_cn_lu",
4+
"applicationId": "=settings.luis.foo_zh_cn_lu.appId",
5+
"version": "=settings.luis.foo_zh_cn_lu.version",
56
"endpoint": "=settings.luis.endpoint",
67
"endpointKey": "=settings.luis.endpointKey"
78
}

0 commit comments

Comments
 (0)