8000 qna properly filters score of 0 · zigri2612/botbuilder-python@4276a80 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4276a80

Browse files
committed
qna properly filters score of 0
1 parent 8cb2bd2 commit 4276a80

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,7 @@ async def _format_qna_result(self, result, options: QnAMakerOptions) -> [QueryRe
305305
json_res = await result.json()
306306

307307
answers_within_threshold = [
308-
{ **answer,'score': answer['score']/100 }
309-
if answer['score']/100 > options.score_threshold
310-
else {**answer} for answer in json_res['answers']
308+
{ **answer,'score': answer['score']/100 } for answer in json_res['answers'] if answer['score']/100 > options.score_threshold
311309
]
312310
sorted_answers = sorted(answers_within_threshold, key = lambda ans: ans['score'], reverse = True)
313311

libraries/botbuilder-ai/tests/qna/test_qna.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,17 @@ async def test_telemetry_returns_answer_when_no_answer_found_in_kb(self):
298298
telemetry_client = unittest.mock.create_autospec(BotTelemetryClient)
299299
qna = QnAMaker(QnaApplicationTest.tests_endpoint, telemetry_client=telemetry_client, log_personal_information=True)
300300
context = QnaApplicationTest._get_context(question, TestAdapter())
301-
301+
302302
# Act
303303
with patch('aiohttp.ClientSession.post', return_value = aiounittest.futurized(response_json)):
304304
results = await qna.get_answers(context)
305305

306306
telemetry_args = telemetry_client.track_event.call_args_list[0][1]
307307
telemetry_properties = telemetry_args['properties']
308-
telemetry_metrics = telemetry_args['measurements']
309308
number_of_args = len(telemetry_args)
310-
first_answer = telemetry_args['properties'][QnATelemetryConstants.answer_property][0]
311-
expected_answer = 'No good match found in KB.'
309+
first_answer = telemetry_args['properties'][QnATelemetryConstants.answer_property]
310+
expected_answer = 'No Qna Answer matched'
311+
expected_matched_question = 'No Qna Question matched'
312312

313313
# Assert - Check Telemetry logged.
314314
self.assertEqual(1, telemetry_client.track_event.call_count)
@@ -317,18 +317,16 @@ async def test_telemetry_returns_answer_when_no_answer_found_in_kb(self):
317317
self.assertTrue('answer' in telemetry_properties)
318318
self.assertTrue('knowledgeBaseId' in telemetry_properties)
319319
self.assertTrue('matchedQuestion' in telemetry_properties)
320+
self.assertEqual(expected_matched_question, telemetry_properties[QnATelemetryConstants.matched_question_property])
320321
self.assertTrue('question' in telemetry_properties)
321322
self.assertTrue('questionId' in telemetry_properties)
322323
self.assertTrue('articleFound' in telemetry_properties)
323324
self.assertEqual(expected_answer, first_answer)
324-
self.assertTrue('score' in telemetry_metrics)
325-
self.assertEqual(0, telemetry_metrics['score'][0])
326325

327326
# Assert - Validate we didn't break QnA functionality.
328327
self.assertIsNotNone(results)
329-
self.assertEqual(1, len(results))
330-
self.assertEqual(expected_answer, results[0].answer[0])
331-
self.assertEqual(None, results[0].source)
328+
self.assertEqual(0, len(results))
329+
332330

333331
async def test_telemetry_pii(self):
334332
# Arrange

0 commit comments

Comments
 (0)
0