예제 #1
0
    def test_qa_mocked_celery(self, *args):
        with self.assertRaises(AuthorizationIsRequired):
            qa_handler("", self.knowledge_base_id, "question", "en")
        with self.assertRaises(EmptyInputException):
            qa_handler(self.authorization, self.knowledge_base_id, "", "en")
        with self.assertRaises(EmptyInputException):
            qa_handler(self.authorization, self.knowledge_base_id, None, "en")
        with self.assertRaises(EmptyInputException):
            qa_handler(self.authorization, self.knowledge_base_id, 23, "en")

        qa_handler(self.authorization, self.knowledge_base_id, "question",
                   "en")
예제 #2
0
 def test_invalid_auth(self):
     with self.assertRaises(AuthorizationIsRequired):
         qa_handler("", self.knowledge_base_id, "question", "en")
     with self.assertRaises(AuthorizationIsRequired):
         qa_handler(3, self.knowledge_base_id, "question", "en")
     with self.assertRaises(AuthorizationIsRequired):
         qa_handler(None, self.knowledge_base_id, "question", "en")
예제 #3
0
 def test_invalid_question(self):
     with self.assertRaises(EmptyInputException):
         qa_handler(self.authorization, self.knowledge_base_id, "",
                    self.language)
     with self.assertRaises(EmptyInputException):
         qa_handler(self.authorization, self.knowledge_base_id, None,
                    self.language)
     with self.assertRaises(EmptyInputException):
         qa_handler(self.authorization, self.knowledge_base_id, 3,
                    self.language)
예제 #4
0
 def test_invalid_language(self):
     with self.assertRaises(ValidationError):
         qa_handler(self.authorization, self.knowledge_base_id, "question",
                    "invalid_language")
     with self.assertRaises(ValidationError):
         qa_handler(self.authorization, self.knowledge_base_id, "question",
                    None)
     with self.assertRaises(ValidationError):
         qa_handler(self.authorization, self.knowledge_base_id, "question",
                    3)
예제 #5
0
    async def question_answering_handler(
            item: QuestionAnsweringRequest,
            request: Request = Depends(AuthorizationRequired()),
            authorization: str = Header(..., description="Bearer your_key"),
            user_agent: str = Header(None),
    ):
        try:
            result = question_answering.qa_handler(
                authorization,
                item.knowledge_base_id,
                item.question,
                item.language,
                user_agent=user_agent,
                from_backend=item.from_backend,
            )
        except QuestionAnsweringException as err:
            raise HTTPException(status_code=400, detail=err.__str__())
        if result.get("status") and result.get("error"):
            raise HTTPException(status_code=400, detail=result)

        return result
예제 #6
0
 def test_question_limit(self):
     with self.assertRaises(LargeQuestionException):
         qa_handler(self.authorization, self.knowledge_base_id,
                    "a" * (BOTHUB_NLP_API_QA_QUESTION_LIMIT + 1),
                    self.language)
예제 #7
0
 def test_qa_mocked_celery_timeout(self, *args):
     with self.assertRaises(CeleryTimeoutException):
         qa_handler(self.authorization, self.knowledge_base_id, "question",
                    "pt_br")
예제 #8
0
 def test_empty_text(self, *args):
     with self.assertRaises(EmptyBaseException):
         qa_handler(self.authorization, self.knowledge_base_id,
                    self.question, self.language)
예제 #9
0
 def test_text_limit(self, *args):
     with self.assertRaises(LargeContextException):
         qa_handler(self.authorization, self.knowledge_base_id,
                    self.question, self.language)