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

Commit 71aaf0d

Browse files
[R10] fix issues #770 and #778 (#785)
* fix pattern issue in cross train * fix bugs * fix posttest * refactor endpoint logic and add tests Co-authored-by: Vishwac Sena Kannan <[email protected]>
1 parent a02f217 commit 71aaf0d

File tree

4 files changed

+88
-15
lines changed

4 files changed

+88
-15
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,20 @@ export class Builder {
4343
let fileName: string
4444
const luFiles = await fileHelper.getLuObjects(undefined, file, true, fileExtEnum.LUFile)
4545

46+
let cultureFromPath = fileHelper.getCultureFromPath(file)
47+
if (cultureFromPath) {
48+
fileCulture = cultureFromPath
49+
let fileNameWithCulture = path.basename(file, path.extname(file))
50+
fileName = fileNameWithCulture.substring(0, fileNameWithCulture.length - fileCulture.length - 1)
51+
} else {
52+
fileCulture = culture
53+
fileName = path.basename(file, path.extname(file))
54+
}
55+
4656
let fileContent = ''
4757
let result
4858
try {
49-
result = await LuisBuilderVerbose.build(luFiles, true, culture)
59+
result = await LuisBuilderVerbose.build(luFiles, true, fileCulture)
5060
fileContent = result.parseToLuContent()
5161
} catch (err) {
5262
if (err.source) {
@@ -58,15 +68,6 @@ export class Builder {
5868
}
5969

6070
this.handler(`${file} loaded\n`)
61-
let cultureFromPath = fileHelper.getCultureFromPath(file)
62-
if (cultureFromPath) {
63-
fileCulture = cultureFromPath
64-
let fileNameWithCulture = path.basename(file, path.extname(file))
65-
fileName = fileNameWithCulture.substring(0, fileNameWithCulture.length - fileCulture.length - 1)
66-
} else {
67-
fileCulture = result.culture !== 'en-us' ? result.culture : culture
68-
fileName = path.basename(file, path.extname(file))
69-
}
7071

7172
const fileFolder = path.dirname(file)
7273
const multiRecognizerPath = path.join(fileFolder, `${fileName}.lu.dialog`)
@@ -122,7 +123,7 @@ export class Builder {
122123
luContents: any[],
123124
recognizers: Map<string, Recognizer>,
124125
authoringKey: string,
125-
region: string,
126+
endpoint: string,
126127
botName: string,
127128
suffix: string,
128129
fallbackLocale: string,
@@ -136,7 +137,7 @@ export class Builder {
136137
// set luis call delay duration to 1100 millisecond because 1000 can hit corner case of rate limit
137138
let delayDuration = 1100
138139

139-
const luBuildCore = new LuBuildCore(authoringKey, `https://${region}.api.cognitive.microsoft.com`)
140+
const luBuildCore = new LuBuildCore(authoringKey, endpoint)
140141
const apps = await luBuildCore.getApplicationList()
141142

142143
// here we do a while loop to make full use of luis tps capacity

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ export default class LuisBuild extends Command {
6666
}
6767

6868
// Flags override userConfig
69-
let {inVal, authoringKey, botName, region, out, defaultCulture, fallbackLocale, suffix, dialog, force, luConfig, deleteOldVersion, log}
70-
= await utils.processInputs(flags, Object.keys(LuisBuild.flags), this.config.configDir)
69+
let luisBuildFlags = Object.keys(LuisBuild.flags)
70+
luisBuildFlags.push('endpoint')
71+
72+
let {inVal, authoringKey, botName, region, out, defaultCulture, fallbackLocale, suffix, dialog, force, luConfig, deleteOldVersion, log, endpoint}
73+
= await utils.processInputs(flags, luisBuildFlags, this.config.configDir)
7174

7275
flags.stdin = await this.readStdin()
7376

@@ -92,6 +95,8 @@ export default class LuisBuild extends Command {
9295
suffix = suffix && suffix !== '' ? suffix : await username() || 'development'
9396
fallbackLocale = fallbackLocale && fallbackLocale !== '' ? fallbackLocale : 'en-us'
9497

98+
endpoint = endpoint && endpoint !== '' ? endpoint : `https://${region}.api.cognitive.microsoft.com`
99+
95100
// create builder class
96101
const builder = new Builder((input: string) => {
97102
if (log) this.log(input)
@@ -134,7 +139,7 @@ export default class LuisBuild extends Command {
134139

135140
// update or create and then train and publish luis applications based on loaded resources
136141
if (log) this.log('Handling applications...')
137-
const dialogContents = await builder.build(luContents, recognizers, authoringKey, region, botName, flags.suffix, fallbackLocale, deleteOldVersion, multiRecognizers, settings)
142+
const dialogContents = await builder.build(luContents, recognizers, authoringKey, endpoint, botName, flags.suffix, fallbackLocale, deleteOldVersion, multiRecognizers, settings)
138143

139144
// write dialog assets based on config
140145
if (dialog) {

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,4 +768,65 @@ describe('luis:build update application succeed with parameters set from luconfi
768768
expect(await compareFiles('./../../../results/test.en-us.lu.dialog', './../../fixtures/testcases/lubuild/luconfig/dialogs/test.en-us.lu.dialog')).to.be.true
769769
expect(await compareFiles('./../../../results/test.lu.dialog', './../../fixtures/testcases/lubuild/luconfig/dialogs/test.lu.dialog')).to.be.true
770770
})
771+
})
772+
773+
describe('luis:build create a new application successfully with locale set to it-it', () => {
774+
before(async function () {
775+
await fs.ensureDir(path.join(__dirname, './../../../results/'))
776+
777+
nock('https://westus.api.cognitive.microsoft.com')
778+
.get(uri => uri.includes('apps'))
779+
.reply(200, [{
780+
name: 'test.en-us.lu',
781+
id: 'f8c64e2a-1111-3a09-8f78-39d7adc76ec5'
782+
}])
783+
784+
nock('https://westus.api.cognitive.microsoft.com')
785+
.post(uri => uri.includes('import'))
786+
.reply(201, {
787+
appId: 'f8c64e2a-2222-3a09-8f78-39d7adc76ec5'
788+
})
789+
790+
nock('https://westus.api.cognitive.microsoft.com')
791+
.post(uri => uri.includes('train'))
792+
.reply(202, {
793+
statusId: 2,
794+
status: 'UpToDate'
795+
})
796+
797+
nock('https://westus.api.cognitive.microsoft.com')
798+
.get(uri => uri.includes('train'))
799+
.reply(200, [{
800+
modelId: '99999',
801+
details: {
802+
statusId: 0,
803+
status: 'Success',
804+
exampleCount: 0
805+
}
806+
}])
807+
808+
nock('https://westus.api.cognitive.microsoft.com')
809+
.post(uri => uri.includes('publish'))
810+
.reply(201, {
811+
versionId: '0.2',
812+
isStaging: true
813+
})
814+
})
815+
816+
after(async function () {
817+
await fs.remove(path.join(__dirname, './../../../results/'))
818+
})
819+
820+
test.only()
821+
.stdout()
822+
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/file-with-personName/personName.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development', '--out', './results', '--defaultCulture', 'it-it'])
823+
.it('should create a new application successfully for prebuilt entity personName with locale set to it-it', ctx => {
824+
expect(ctx.stdout).to.contain('Handling applications...')
825+
expect(ctx.stdout).to.contain('Creating LUIS.ai application')
826+
expect(ctx.stdout).to.contain('training version=0.1')
827+
expect(ctx.stdout).to.contain('waiting for training for version=0.1')
828+
expect(ctx.stdout).to.contain('publishing version=0.1')
829+
expect(ctx.stdout).to.contain('publishing finished')
830+
expect(ctx.stdout.includes('personName is not available for the requested locale: it-it')).to.be.false
831+
})
771832
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# UserProfile
2+
- get started
3+
- my name is {@userName}
4+
- Profile
5+
6+
@ prebuilt personName hasRoles userName

0 commit comments

Comments
 (0)