async def test_low_score_variation(self): qna = QnAMaker(QnaApplicationTest.tests_endpoint) options = QnAMakerOptions(top=5, context=None) turn_context = QnaApplicationTest._get_context("Q11", TestAdapter()) response_json = QnaApplicationTest._get_json_for_file( "QnaMaker_TopNAnswer.json") # active learning enabled with patch( "aiohttp.ClientSession.post", return_value=aiounittest.futurized(response_json), ): results = await qna.get_answers(turn_context, options) self.assertIsNotNone(results) self.assertEqual(4, len(results), "should get four results") filtered_results = qna.get_low_score_variation(results) self.assertIsNotNone(filtered_results) self.assertEqual(3, len(filtered_results), "should get three results") # active learning disabled turn_context = QnaApplicationTest._get_context("Q11", TestAdapter()) response_json = QnaApplicationTest._get_json_for_file( "QnaMaker_TopNAnswer_DisableActiveLearning.json") with patch( "aiohttp.ClientSession.post", return_value=aiounittest.futurized(response_json), ): results = await qna.get_answers(turn_context, options) self.assertIsNotNone(results) self.assertEqual(4, len(results), "should get four results") filtered_results = qna.get_low_score_variation(results) self.assertIsNotNone(filtered_results) self.assertEqual(3, len(filtered_results), "should get three results")
async def test_should_filter_low_score_variation(self): options = QnAMakerOptions(top=5) qna = QnAMaker(QnaApplicationTest.tests_endpoint, options) question: str = "Q11" context = QnaApplicationTest._get_context(question, TestAdapter()) response_json = QnaApplicationTest._get_json_for_file("TopNAnswer.json") with patch( "aiohttp.ClientSession.post", return_value=aiounittest.futurized(response_json), ): results = await qna.get_answers(context) self.assertEqual(4, len(results), "Should have received 4 answers.") filtered_results = qna.get_low_score_variation(results) self.assertEqual( 3, len(filtered_results), "Should have 3 filtered answers after low score variation.", )