Skip to content

Commit

Permalink
fix: [#4288] CustomQuestionAnswering answers return empty metadata (#…
Browse files Browse the repository at this point in the history
…4311)

* Fix bad formatting of metadata object

* Add unit test for metadata
  • Loading branch information
ceciliaavila authored Aug 26, 2022
1 parent 70990c5 commit 403b4f7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class LanguageServiceUtils {
answer: kbAnswer.answer,
score: kbAnswer.confidenceScore,
metadata: kbAnswer.metadata
? Array.from(kbAnswer.metadata)?.map((nv) => {
? Object.entries(kbAnswer.metadata).map((nv) => {
return { name: nv[0], value: nv[1] };
})
: null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"answers": [
{
"confidenceScore": 0.4854820341616869,
"Id": 20,
"answer": "They're frolicking merrily in the verdant garden!",
"source": "Custom Editorial",
"questions": [
"where are the unicorns?"
],
"metadata": {
"title": "mythical unicorns"
}
}
]
}
13 changes: 13 additions & 0 deletions libraries/botbuilder-ai/tests/languageService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ describe('LanguageService', function () {
const results = await qna.getAnswers(context, options);
assert.strictEqual(results.length, 1);
});

it('returns answer without any options specified', async function () {
const qna = new CustomQuestionAnswering(endpoint);
const context = new TestContext({ text: 'where are the unicorns?' });
Expand All @@ -230,6 +231,18 @@ describe('LanguageService', function () {
assert.strictEqual(results.length, 1);
});

it('returns answer with metadata', async function () {
const qna = new CustomQuestionAnswering(endpoint);
const context = new TestContext({ text: 'where are the unicorns?' });

const results = await qna.getAnswers(context);

assert.strictEqual(results.length, 1);
assert.strictEqual(results[0].metadata.length, 1);
assert.strictEqual(results[0].metadata[0].name, 'title');
assert.strictEqual(results[0].metadata[0].value, 'mythical unicorns');
});

it('returns answer and active learning flag', async function () {
const qna = new CustomQuestionAnswering(endpoint);
const context = new TestContext({ text: 'where are the unicorns?' });
Expand Down

0 comments on commit 403b4f7

Please sign in to comment.