Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions packages/lu/src/parser/qnabuild/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ export class Builder {
// otherwise create a new kb
if (recognizer.getKBId() && recognizer.getKBId() !== '') {
// To see if need update the model
needPublish = await this.updateKB(currentKB, content.content, qnaBuildCore, recognizer, currentKB.name, delayDuration)
needPublish = await this.updateKB(currentKB, qnaBuildCore, recognizer, delayDuration)
} else {
// create a new kb
needPublish = await this.createKB(content.content, qnaBuildCore, recognizer, currentKB.name, delayDuration)
needPublish = await this.createKB(currentKB, qnaBuildCore, recognizer, delayDuration)
}

if (needPublish) {
Expand Down Expand Up @@ -315,36 +315,36 @@ export class Builder {
return {kb: currentQna.kb, alterations: currentQna.alterations}
}

async updateKB(currentKB: any, qnaContent: string, qnaBuildCore: QnaBuildCore, recognizer: Recognizer, kbName: string, delayDuration: number) {
async updateKB(currentKB: any, qnaBuildCore: QnaBuildCore, recognizer: Recognizer, delayDuration: number) {
await delay(delayDuration)
const existingKB = await qnaBuildCore.exportKB(recognizer.getKBId(), 'Prod')

// compare models
const isKBEqual = qnaBuildCore.isKBEqual(currentKB, existingKB)
if (!isKBEqual) {
try {
this.handler(`Updating to new version for kb ${kbName}...\n`)
this.handler(`Updating to new version for kb ${currentKB.name}...\n`)
await delay(delayDuration)
await qnaBuildCore.replaceKB(recognizer.getKBId(), qnaContent)
await qnaBuildCore.replaceKB(recognizer.getKBId(), currentKB)

this.handler(`Updating finished for kb ${kbName}\n`)
this.handler(`Updating finished for kb ${currentKB.name}\n`)
} catch (err) {
err.text = `Updating knowledge base failed: \n${err.text}`
throw err
}

return true
} else {
this.handler(`kb ${kbName} has no changes\n`)
this.handler(`kb ${currentKB.name} has no changes\n`)
return false
}
}

async createKB(qnaContent: string, qnaBuildCore: QnaBuildCore, recognizer: Recognizer, kbName: string, delayDuration: number) {
this.handler(`Creating qnamaker KB: ${kbName}...\n`)
async createKB(currentKB: any, qnaBuildCore: QnaBuildCore, recognizer: Recognizer, delayDuration: number) {
this.handler(`Creating qnamaker KB: ${currentKB.name}...\n`)
await delay(delayDuration)
const emptyKBJson = {
name: kbName,
name: currentKB.name,
qnaList: [],
urls: [],
files: []
Expand All @@ -356,9 +356,9 @@ export class Builder {
const opResult = await this.getKBOperationStatus(qnaBuildCore, operationId, delayDuration)
recognizer.setKBId(opResult.resourceLocation.split('/')[2])
await delay(delayDuration)
await qnaBuildCore.replaceKB(recognizer.getKBId(), qnaContent)
await qnaBuildCore.replaceKB(recognizer.getKBId(), currentKB)

this.handler(`Creating finished for kb ${kbName}\n`)
this.handler(`Creating finished for kb ${currentKB.name}\n`)
} catch (err) {
err.text = `Creating knowledge base failed: \n${err.text}`
throw err
Expand Down
2 changes: 1 addition & 1 deletion packages/lu/src/parser/qnabuild/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class QnaBuildCore {
id: qna.id,
answer: qna.answer,
source: qna.source,
questions: qna.questions,
questions: qna.questions.slice(),
metadata: qna.metadata,
context: qna.context
}
Expand Down
3 changes: 1 addition & 2 deletions packages/qnamaker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ OPTIONS

EXAMPLE

$ bf qnamaker:build --in {INPUT_FILE_OR_FOLDER} --subscriptionKey {SUBSCRIPTION_KEY} --botName {BOT_NAME}
--dialog
$ bf qnamaker:build --in {INPUT_FILE_OR_FOLDER} --subscriptionKey {SUBSCRIPTION_KEY} --botName {BOT_NAME}
```

_See code: [src/commands/qnamaker/build.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/qnamaker/src/commands/qnamaker/build.ts)_
Expand Down
12 changes: 11 additions & 1 deletion packages/qnamaker/src/commands/qnamaker/kb/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
*/

import {CLIError, Command, flags} from '@microsoft/bf-cli-command'
import {Inputs, processInputs} from '../../../utils/qnamakerbase'

const qnaBuilderVerbose = require('@microsoft/bf-lu/lib/parser/qna/qnamaker/kbCollate')
const qnaMakerBuilder = require('@microsoft/bf-lu/lib/parser/qna/qnamaker/qnaMakerBuilder')
const fileHelper = require('@microsoft/bf-lu/lib/utils/filehelper')
const fileExtEnum = require('@microsoft/bf-lu/lib/parser/utils/helpers').FileExtTypeEnum
const qnamaker = require('./../../../../utils/index')
const replaceKbJSON = require('./../../../../utils/payloads/replacekb')
import {Inputs, processInputs} from '../../../utils/qnamakerbase'

export default class QnamakerKbReplace extends Command {
static description = 'Replace a knowledgebase contents with new contents'
Expand All @@ -32,6 +36,12 @@ export default class QnamakerKbReplace extends Command {
if (input.requestBody.qnaDocuments && !input.requestBody.qnaList) {
input.requestBody.qnaList = input.requestBody.qnaDocuments
delete input.requestBody.qnaDocuments
} else if (flags.qnaFormat) {
const qnaFiles = await fileHelper.getLuObjects(stdin, flags.in, false, fileExtEnum.QnAFile)
const result = await qnaBuilderVerbose.build(qnaFiles)
const qnamaker = await qnaMakerBuilder.fromContent(result.parseToQnAContent())
input.requestBody = qnamaker ? JSON.parse(JSON.stringify(qnamaker.kb)) : undefined
flags.qnaFormat = false
}

const result = await qnamaker(input.config, input.serviceManifest, flags, input.requestBody)
Expand Down