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

Commit c2db878

Browse files
resolve luis build issues (#804)
* luis build do not write dialogs if no --out specified * qnamaker:build do not write .dialog if no --out is specified * fix suffix issue in luis build * revert qnamaker changes in this PR and add to another * fix typo Co-authored-by: Emilio Munoz <[email protected]>
1 parent 854190a commit c2db878

File tree

3 files changed

+27
-66
lines changed

3 files changed

+27
-66
lines changed

packages/luis/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,13 @@ USAGE
339339
$ bf luis:build
340340
341341
OPTIONS
342-
-f, --force If --dialog flag is provided, overwrites relevant dialog file
342+
-f, --force If --out flag is provided, overwrites relevant dialog file
343343
-h, --help show CLI help
344344
-i, --in=in Lu file or folder
345345
346-
-o, --out=out Output file or folder name. If not specified, current directory will be used as
347-
output
348-
346+
-o, --out=out Output folder name to write out .dialog files. If not specified, application
347+
ids will be output to console
348+
349349
--authoringKey=authoringKey LUIS authoring key
350350
351351
--botName=botName Bot name
@@ -354,11 +354,10 @@ OPTIONS
354354
355355
--deleteOldVersion Delete old version of LUIS application after building new one.
356356
357-
--dialog=dialog [default: multiLanguage] Write out .dialog files whose recognizer type
358-
[multiLanguage|crosstrained] is specified by --dialog
357+
--dialog=dialog [default: multiLanguage] Dialog recognizer type [multiLanguage|crosstrained]
359358
360359
--fallbackLocale=fallbackLocale Locale to be used at the fallback if no locale specific recognizer is found. Only
361-
valid if --dialog is set
360+
valid if --out is set
362361
363362
--log write out log messages to console
364363

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ export default class LuisBuild extends Command {
3232
authoringKey: flags.string({description: 'LUIS authoring key'}),
3333
botName: flags.string({description: 'Bot name'}),
3434
region: flags.string({description: 'LUIS authoring region [westus|westeurope|australiaeast]', default: 'westus'}),
35-
out: flags.string({char: 'o', description: 'Output file or folder name. If not specified, current directory will be used as output'}),
35+
out: flags.string({char: 'o', description: 'Output folder name to write out .dialog files. If not specified, application ids will be output to console'}),
3636
defaultCulture: flags.string({description: 'Culture code for the content. Infer from .lu if available. Defaults to en-us'}),
37-
fallbackLocale: flags.string({description: 'Locale to be used at the fallback if no locale specific recognizer is found. Only valid if --dialog is set'}),
37+
fallbackLocale: flags.string({description: 'Locale to be used at the fallback if no locale specific recognizer is found. Only valid if --out is set'}),
3838
suffix: flags.string({description: 'Environment name as a suffix identifier to include in LUIS app name. Defaults to current logged in user alias'}),
39-
dialog: flags.string({description: 'Write out .dialog files whose recognizer type [multiLanguage|crosstrained] is specified by --dialog', default: 'multiLanguage'}),
40-
force: flags.boolean({char: 'f', description: 'If --dialog flag is provided, overwrites relevant dialog file', default: false}),
39+
dialog: flags.string({description: 'Dialog recognizer type [multiLanguage|crosstrained]', default: 'multiLanguage'}),
40+
force: flags.boolean({char: 'f', description: 'If --out flag is provided, overwrites relevant dialog file', default: false}),
4141
luConfig: flags.string({description: 'Path to config for lu build which can contain switches for arguments'}),
4242
deleteOldVersion: flags.boolean({description: 'Delete old version of LUIS application after building new one.'}),
4343
log: flags.boolean({description: 'write out log messages to console', default: false}),
@@ -139,13 +139,12 @@ export default class LuisBuild extends Command {
139139

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

144144
// write dialog assets based on config
145-
if (dialog) {
146-
const writeDone = await builder.writeDialogAssets(dialogContents, force, out, dialog, luConfig)
147-
const dialogFilePath = (flags.stdin || !inVal) ? process.cwd() : inVal.endsWith(fileExtEnum.LUFile) ? path.dirname(path.resolve(inVal)) : path.resolve(inVal)
148-
const outputFolder = out ? path.resolve(out) : dialogFilePath
145+
if (out) {
146+
const outputFolder = path.resolve(out)
147+
const writeDone = await builder.writeDialogAssets(dialogContents, force, outputFolder, dialog, luConfig)
149148
if (writeDone) {
150149
this.log(`Successfully wrote .dialog files to ${outputFolder}\n`)
151150
} else {

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

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ describe('luis:build cli parameters test', () => {
7373
})
7474

7575
describe('luis:build create a new application successfully', () => {
76-
before(async function () {
77-
await fs.ensureDir(path.join(__dirname, './../../../results/'))
78-
76+
before(function () {
7977
nock('https://westus.api.cognitive.microsoft.com')
8078
.get(uri => uri.includes('apps'))
8179
.reply(200, [{
@@ -115,13 +113,9 @@ describe('luis:build create a new application successfully', () => {
115113
})
116114
})
117115

118-
after(async function () {
119-
await fs.remove(path.join(__dirname, './../../../results/'))
120-
})
121-
122116
test
123117
.stdout()
124-
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich//lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development', '--out', './results'])
118+
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich//lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development'])
125119
.it('should create a new application successfully', ctx => {
126120
expect(ctx.stdout).to.contain('Handling applications...')
127121
expect(ctx.stdout).to.contain('Creating LUIS.ai application')
@@ -134,9 +128,7 @@ describe('luis:build create a new application successfully', () => {
134128

135129
describe('luis:build update application succeed when utterances changed', () => {
136130
const existingLuisApp = require('./../../fixtures/testcases/lubuild/sandwich/luis/test(development)-sandwich.utteranceChanged.en-us.lu.json')
137-
before(async function () {
138-
await fs.ensureDir(path.join(__dirname, './../../../results/'))
139-
131+
before(function () {
140132
nock('https://westus.api.cognitive.microsoft.com')
141133
.get(uri => uri.includes('apps'))
142134
.reply(200, [{
@@ -186,13 +178,9 @@ describe('luis:build update application succeed when utterances changed', () =>
186178
})
187179
})
188180

189-
after(async function () {
190-
await fs.remove(path.join(__dirname, './../../../results/'))
191-
})
192-
193181
test
194182
.stdout()
195-
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich/lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development', '--out', './results'])
183+
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich/lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development'])
196184
.it('should update a luis application when utterances changed', ctx => {
197185
expect(ctx.stdout).to.contain('Handling applications...')
198186
expect(ctx.stdout).to.contain('creating version=0.2')
@@ -205,9 +193,7 @@ describe('luis:build update application succeed when utterances changed', () =>
205193

206194
describe('luis:build update application succeed when utterances added', () => {
207195
const existingLuisApp = require('./../../fixtures/testcases/lubuild/sandwich/luis/test(development)-sandwich.utteranceAdded.en-us.lu.json')
208-
before(async function () {
209-
await fs.ensureDir(path.join(__dirname, './../../../results/'))
210-
196+
before(function () {
211197
nock('https://westus.api.cognitive.microsoft.com')
212198
.get(uri => uri.includes('apps'))
213199
.reply(200, [{
@@ -257,13 +243,9 @@ describe('luis:build update application succeed when utterances added', () => {
257243
})
258244
})
259245

260-
after(async function () {
261-
await fs.remove(path.join(__dirname, './../../../results/'))
262-
})
263-
264246
test
265247
.stdout()
266-
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich/lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development', '--out', './results'])
248+
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich/lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development'])
267249
.it('should update a luis application when utterances added', ctx => {
268250
expect(ctx.stdout).to.contain('Handling applications...')
269251
expect(ctx.stdout).to.contain('creating version=0.2')
@@ -276,9 +258,7 @@ describe('luis:build update application succeed when utterances added', () => {
276258

277259
describe('luis:build not update application if no changes', () => {
278260
const existingLuisApp = require('./../../fixtures/testcases/lubuild/sandwich/luis/test(development)-sandwich.en-us.lu.json')
279-
before(async function () {
280-
await fs.ensureDir(path.join(__dirname, './../../../results/'))
281-
261+
before(function () {
282262
nock('https://westus.api.cognitive.microsoft.com')
283263
.get(uri => uri.includes('apps'))
284264
.reply(200, [{
@@ -299,13 +279,9 @@ describe('luis:build not update application if no changes', () => {
299279
.reply(200, existingLuisApp)
300280
})
301281

302-
after(async function () {
303-
await fs.remove(path.join(__dirname, './../../../results/'))
304-
})
305-
306282
test
307283
.stdout()
308-
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich/lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development', '--out', './results'])
284+
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich/lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development'])
309285
.it('should not update a luis application when there are no changes for the coming lu file', ctx => {
310286
expect(ctx.stdout).to.contain('Handling applications...')
311287
expect(ctx.stdout).to.contain('no changes')
@@ -343,7 +319,7 @@ describe('luis:build write dialog assets successfully if --dialog set to multiLa
343319

344320
test
345321
.stdout()
346-
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich/lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--dialog', 'multiLanguage', '--out', './results', '--log', '--suffix', 'development'])
322+
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich/lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--out', './results', '--log', '--suffix', 'development'])
347323
.it('should write dialog assets successfully when --dialog set to multiLanguage', async ctx => {
348324
expect(await compareFiles('./../../../results/luis.settings.development.westus.json', './../../fixtures/testcases/lubuild/sandwich/config/luis.settings.development.westus.json')).to.be.true
349325
expect(await compareFiles('./../../../results/sandwich.en-us.lu.dialog', './../../fixtures/testcases/lubuild/sandwich/dialogs/sandwich.en-us.lu.dialog')).to.be.true
@@ -642,9 +618,7 @@ describe('luis:build update dialog assets successfully when dialog assets exist'
642618

643619
describe('luis:build not update application if only cases of utterances or patterns are changed', () => {
644620
const existingLuisApp = require('./../../fixtures/testcases/lubuild/case-insensitive/luis/test(development)-case-insensitive.en-us.lu.json')
645-
before(async function () {
646-
await fs.ensureDir(path.join(__dirname, './../../../results/'))
647-
621+
before(function () {
648622
nock('https://westus.api.cognitive.microsoft.com')
649623
.get(uri => uri.includes('apps'))
650624
.reply(200, [{
@@ -665,13 +639,9 @@ describe('luis:build not update application if only cases of utterances or patte
665639
.reply(200, existingLuisApp)
666640
})
667641

668-
after(async function () {
669-
await fs.remove(path.join(__dirname, './../../../results/'))
670-
})
671-
672642
test
673643
.stdout()
674-
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/case-insensitive/lufiles/case-insensitive.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development', '--out', './results'])
644+
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/case-insensitive/lufiles/case-insensitive.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development'])
675645
.it('should not update a luis application when only cases of utterances or patterns are different for the coming lu file', ctx => {
676646
expect(ctx.stdout).to.contain('Handling applications...')
677647
expect(ctx.stdout).to.contain('no changes')
@@ -755,7 +725,6 @@ describe('luis:build update application succeed with parameters set from luconfi
755725
.stdout()
756726
.command(['luis:build', '--authoringKey', uuidv1(), '--luConfig', './test/fixtures/testcases/lubuild/luconfig/lufiles/luconfig.json', '--log', '--suffix', 'development'])
757727
.it('should update a luis application when utterances changed', async ctx => {
758-
console.log(ctx)
759728
expect(ctx.stdout).to.contain('Handling applications...')
760729
expect(ctx.stdout).to.contain('creating version=0.2')
761730
expect(ctx.stdout).to.contain('deleting old version=0.1')
@@ -771,9 +740,7 @@ describe('luis:build update application succeed with parameters set from luconfi
771740
})
772741

773742
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-
743+
before(function () {
777744
nock('https://westus.api.cognitive.microsoft.com')
778745
.get(uri => uri.includes('apps'))
779746
.reply(200, [{
@@ -813,13 +780,9 @@ describe('luis:build create a new application successfully with locale set to it
813780
})
814781
})
815782

816-
after(async function () {
817-
await fs.remove(path.join(__dirname, './../../../results/'))
818-
})
819-
820783
test
821784
.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'])
785+
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/file-with-personName/personName.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development', '--defaultCulture', 'it-it'])
823786
.it('should create a new application successfully for prebuilt entity personName with locale set to it-it', ctx => {
824787
expect(ctx.stdout).to.contain('Handling applications...')
825788
expect(ctx.stdout).to.contain('Creating LUIS.ai application')

0 commit comments

Comments
 (0)