Пример #1
0
    def test_options_passed_to_ctor(self):
        options = QnAMakerOptions(
            score_threshold=0.8,
            timeout=9000,
            top=5,
            strict_filters=[Metadata("movie", "disney")],
        )

        qna_with_options = QnAMaker(self.tests_endpoint, options)
        actual_options = qna_with_options._generate_answer_helper.options

        expected_threshold = 0.8
        expected_timeout = 9000
        expected_top = 5
        expected_strict_filters = [Metadata("movie", "disney")]

        self.assertEqual(expected_threshold, actual_options.score_threshold)
        self.assertEqual(expected_timeout, actual_options.timeout)
        self.assertEqual(expected_top, actual_options.top)
        self.assertEqual(
            expected_strict_filters[0].name, actual_options.strict_filters[0].name
        )
        self.assertEqual(
            expected_strict_filters[0].value, actual_options.strict_filters[0].value
        )
Пример #2
0
    async def test_returns_answer_using_options(self):
        # Arrange
        question: str = "up"
        response_path: str = "AnswerWithOptions.json"
        options = QnAMakerOptions(score_threshold=0.8,
                                  top=5,
                                  strict_filters=[Metadata("movie", "disney")])

        # Act
        result = await QnaApplicationTest._get_service_result(question,
                                                              response_path,
                                                              options=options)

        first_answer = result[0]
        has_at_least_1_ans = True
        first_metadata = first_answer.metadata[0]

        # Assert
        self.assertIsNotNone(result)
        self.assertEqual(has_at_least_1_ans, len(result) >= 1)
        self.assertTrue(first_answer.answer[0])
        self.assertEqual("is a movie", first_answer.answer)
        self.assertTrue(first_answer.score >= options.score_threshold)
        self.assertEqual("movie", first_metadata.name)
        self.assertEqual("disney", first_metadata.value)
Пример #3
0
    async def test_returns_answer_with_strict_filters_with_and_operator(self):
        # Arrange
        question: str = "Where can you find"
        response_path: str = "RetrunsAnswer_WithStrictFilter_And_Operator.json"
        response_json = QnaApplicationTest._get_json_for_file(response_path)

        strict_filters = [
            Metadata(name="species", value="human"),
            Metadata(name="type", value="water"),
        ]
        options = QnAMakerOptions(
            top=5,
            strict_filters=strict_filters,
            strict_filters_join_operator=JoinOperator.AND,
        )
        qna = QnAMaker(endpoint=QnaApplicationTest.tests_endpoint)
        context = QnaApplicationTest._get_context(question, TestAdapter())

        # Act
        with patch(
                "aiohttp.ClientSession.post",
                return_value=aiounittest.futurized(response_json),
        ) as mock_http_client:
            result = await qna.get_answers_raw(context, options)

            serialized_http_req_args = mock_http_client.call_args[1]["data"]
            req_args = json.loads(serialized_http_req_args)

            # Assert
            self.assertIsNotNone(result)
            self.assertEqual(1, len(result.answers))
            self.assertEqual(JoinOperator.AND,
                             req_args["strictFiltersCompoundOperationType"])

            req_args_strict_filters = req_args["strictFilters"]

            first_filter = strict_filters[0]
            self.assertEqual(first_filter.name,
                             req_args_strict_filters[0]["name"])
            self.assertEqual(first_filter.value,
                             req_args_strict_filters[0]["value"])

            second_filter = strict_filters[1]
            self.assertEqual(second_filter.name,
                             req_args_strict_filters[1]["name"])
            self.assertEqual(second_filter.value,
                             req_args_strict_filters[1]["value"])