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
34 changes: 28 additions & 6 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/qnamaker/src/commands/qnamaker/kb/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class QnamakerKbExport extends Command {

static flags: flags.Input<any> = {
kbId: flags.string({description: 'Knowledgebase id to be exported. Overrides the knowledge base id present in the config'}),
qnaFormat: flags.boolean({description: 'Specifies if the content should be exported to .qna format.', default: false}),
environment: flags.string({description: 'Specifies whether environment is Test or Prod.', default: 'Prod'}),
subscriptionKey: flags.string({description: 'Specifies the qnamaker Ocp-Apim-Subscription Key (found in Keys under Resource Management section for your Qna Maker cognitive service). Overrides the subscriptionkey value present in the config'}),
endpoint: flags.string({description: 'Overrides public endpoint https://westus.api.cognitive.microsoft.com/qnamaker/v4.0/'}),
Expand Down
2 changes: 1 addition & 1 deletion packages/qnamaker/src/commands/qnamaker/kb/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class QnamakerKbReplace extends Command {
static description = 'Replace a knowledgebase contents with new contents'

static flags: flags.Input<any> = {
in: flags.string({char: 'i', description: 'File path to the ReplaceKbDTO object to send in the body of the request'}),
in: flags.string({char: 'i', description: 'File path to the ReplaceKbDTO object to send in the body of the request. Alternately this can be path to a .qna file'}),
kbId: flags.string({description: 'Knowledgebase id. Overrides the knowledge base id present in the config'}),
subscriptionKey: flags.string({description: 'Specifies the qnamaker Ocp-Apim-Subscription Key (found in Keys under Resource Management section for your Qna Maker cognitive service). Overrides the subscriptionkey value present in the config'}),
endpoint: flags.string({description: 'Overrides public endpoint https://westus.api.cognitive.microsoft.com/qnamaker/v4.0/'}),
Expand Down
9 changes: 8 additions & 1 deletion packages/qnamaker/src/utils/qnamakerbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const path = require('path')
const qnaconfig = require('./../../utils/qnaconfig')
const srvMan = require('./../../utils/servicemanifest')
const {ServiceBase} = require('./../../utils/api/serviceBase')
const file = require('@microsoft/bf-lu/lib/utils/filehelper')


export async function processInputs(flags: any, payload: any, configfile: string, stdin = '') {
let result: Inputs = {}
Expand All @@ -22,7 +24,12 @@ export async function processInputs(flags: any, payload: any, configfile: string
flags.in = stdin ? stdin : flags.in
result.requestBody = await srvMan.validateArguments(serviceManifest, flags)
if (stdin || flags.in) {
result.requestBody = stdin ? JSON.parse(stdin) : await getFileInput(flags.in)
result.requestBody = stdin || await file.getContentFromFile(flags.in)
try {
result.requestBody = JSON.parse(result.requestBody)
} catch(ex) {
flags.qnaFormat = true
}
}
config.endpoint = flags.endpoint
result.config = config
Expand Down
37 changes: 37 additions & 0 deletions packages/qnamaker/test/commands/qnamaker/kb/export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,40 @@ describe('qnamaker:kb:export', () => {
nock.cleanAll()
})
})

describe('[qnaformat] qnamaker:kb:export', () => {
before(async function () {
await initTestConfigFile()
// runs before all tests in this block
nock('https://westus.api.cognitive.microsoft.com/qnamaker/v4.0')
.get('/knowledgebases/5690998c-4438-4ae1-900a-88a2aa3bfa68/Test/qna?qnaformat=true')
.reply(200,
`## ? I need help
- help
- can you please help
- what can I say
- what can you do?

**Filters:**
- dialogname = adaptivedialog

\`\`\`markdown
Sure. Happy to help!
\`\`\`
`)
})

after(async function () {
await deleteTestConfigFile()
})

test
.stdout()
.command(['qnamaker:kb:export', '--kbId', '5690998c-4438-4ae1-900a-88a2aa3bfa68', '--environment', 'Test', '--qnaFormat'])
.it('Exports kb', ctx => {
console.log(ctx.stdout)
expect(ctx.stdout).to.contain('Sure. Happy to help!')
nock.cleanAll()
})
})

11 changes: 11 additions & 0 deletions packages/qnamaker/test/commands/qnamaker/kb/replace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ describe('qnamaker:kb:replace', () => {
nock('https://westus.api.cognitive.microsoft.com/qnamaker/v4.0')
.put('/knowledgebases/287ce749-012c-4eed-a39c-e4f8f06616cf')
.reply(204)

nock('https://westus.api.cognitive.microsoft.com/qnamaker/v4.0')
.put('/knowledgebases/287ce749-012c-4eed-a39c-e4f8f06616cf?qnaformat=true')
.reply(204)
})

after(async function () {
Expand All @@ -23,6 +27,13 @@ describe('qnamaker:kb:replace', () => {
expect(ctx.stdout).to.equal('')
})

test
.stdout()
.command(['qnamaker:kb:replace', '--kbId', '287ce749-012c-4eed-a39c-e4f8f06616cf', '--in', `${path.join(__dirname, '../../../fixtures/replacekb.qna')}`])
.it('[qnaformat] runs qnamaker:kb:replace --kbId xxxxxxxxxx --in replace.qna', ctx => {
expect(ctx.stdout).to.equal('')
})

test
.stderr()
.command(['qnamaker:kb:replace'])
Expand Down
12 changes: 12 additions & 0 deletions packages/qnamaker/test/fixtures/replacekb.qna
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## ? I need help
- help
- can you please help
- what can I say
- what can you do?

**Filters:**
- dialogname = adaptivedialog

```markdown
Sure. Happy to help!
```
6 changes: 5 additions & 1 deletion packages/qnamaker/utils/api/dataModels/replaceKbDto.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ ReplaceKbDTO.fromJSON = function(src) {
if (Array.isArray(src)) {
return src.map(ReplaceKbDTO.fromJSON);
}

try {
let isJson = JSON.parse(src);
} catch(err) {
return src;
}
src.qnAList = QnADTO.fromJSON(src.qnAList) || QnADTO.fromJSON(src.qnaList) || undefined;

const {qnAList /* QnADTO[] */} = src;
Expand Down
9 changes: 8 additions & 1 deletion packages/qnamaker/utils/api/serviceBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ class ServiceBase {
URL += !isNaN(+skip) ? `&take=${~~take}` : `take=${~~take}`;
}
}
const body = dataModel ? JSON.stringify(dataModel) : undefined;
let body = undefined;
if (params.qnaFormat !== undefined && params.qnaFormat === true) {
URL += URL.includes(`?`) ? `&qnaformat=true` : `?qnaformat=true`
headers["Content-Type"] = `application/text`;
body = dataModel ? dataModel : undefined;
} else if (dataModel) {
body = JSON.stringify(dataModel)
}
if (params.debug) {
console.log(`${method.toUpperCase()} ${URL}`);
if (headers)
Expand Down