diff --git a/Pipfile b/Pipfile index f3f3e3b..7b410bd 100644 --- a/Pipfile +++ b/Pipfile @@ -17,6 +17,7 @@ sentry-sdk = "~=0.13.2" django-environ = "~=0.4.5" email-validator = "~=1.1.1" redis = "~=3.5.3" +python-multipart = "~=0.0.5" [dev-packages] gunicorn = "~=19.9.0" diff --git a/Pipfile.lock b/Pipfile.lock index 29f7ac3..2907862 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "9a2f44e7c67622b7bd87d32132303956006e9ee79166400cca39c3aee4d18917" + "sha256": "b2cf5869bc79cc6de6d380696504b551c462eb4ccd0504b4c827dedcdfb089f7" }, "pipfile-spec": 6, "requires": { @@ -183,11 +183,11 @@ }, "google-api-core": { "hashes": [ - "sha256:108cf94336aed7e614eafc53933ef02adf63b9f0fd87e8f8212acaa09eaca456", - "sha256:1d63e2b28057d79d64795c9a70abcecb5b7e96da732d011abf09606a39b48701" + "sha256:384459a0dc98c1c8cd90b28dc5800b8705e0275a673a7144a513ae80fc77950b", + "sha256:8500aded318fdb235130bf183c726a05a9cb7c4b09c266bd5119b86cdb8a4d10" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", - "version": "==1.31.1" + "version": "==1.31.2" }, "google-api-python-client": { "hashes": [ @@ -199,11 +199,11 @@ }, "google-auth": { "hashes": [ - "sha256:bd6aa5916970a823e76ffb3d5c3ad3f0bedafca0a7fa53bc15149ab21cb71e05", - "sha256:f1094088bae046fb06f3d1a3d7df14717e8d959e9105b79c57725bd4e17597a2" + "sha256:997516b42ecb5b63e8d80f5632c1a61dddf41d2a4c2748057837e06e00014258", + "sha256:b7033be9028c188ee30200b204ea00ed82ea1162e8ac1df4aa6ded19a191d88e" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", - "version": "==1.34.0" + "version": "==1.35.0" }, "google-auth-httplib2": { "hashes": [ @@ -264,11 +264,11 @@ }, "importlib-metadata": { "hashes": [ - "sha256:0645585859e9a6689c523927a5032f2ba5919f1f7d0e84bd4533312320de1ff9", - "sha256:51c6635429c77cf1ae634c997ff9e53ca3438b495f10a55ba28594dd69764a8b" + "sha256:7b30a78db2922d78a6f47fb30683156a14f3c6aa5cc23f77cc8967e9ab2d002f", + "sha256:ed5157fef23a4bc4594615a0dd8eba94b2bb36bf2a343fa3d8bb2fa0a62a99d5" ], "markers": "python_version < '3.8'", - "version": "==4.6.3" + "version": "==4.6.4" }, "kombu": { "hashes": [ @@ -472,6 +472,13 @@ ], "version": "==3.3" }, + "python-multipart": { + "hashes": [ + "sha256:f7bb5f611fc600d15fa47b3974c8aa16e93724513b49b5f95c81e6624c83fa43" + ], + "index": "pypi", + "version": "==0.0.5" + }, "pytz": { "hashes": [ "sha256:83a4a90894bf38e243cf052c8b58f381bfe9a7a483f6a9cab140bc7f702ac4da", @@ -579,11 +586,11 @@ }, "tqdm": { "hashes": [ - "sha256:3642d483b558eec80d3c831e23953582c34d7e4540db86d9e5ed9dad238dabc6", - "sha256:706dea48ee05ba16e936ee91cb3791cd2ea6da348a0e50b46863ff4363ff4340" + "sha256:07856e19a1fe4d2d9621b539d3f072fa88c9c1ef1f3b7dd4d4953383134c3164", + "sha256:35540feeaca9ac40c304e916729e6b78045cbbeccd3e941b2868f09306798ac9" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==4.62.0" + "version": "==4.62.1" }, "typing-extensions": { "hashes": [ @@ -800,11 +807,11 @@ }, "importlib-metadata": { "hashes": [ - "sha256:0645585859e9a6689c523927a5032f2ba5919f1f7d0e84bd4533312320de1ff9", - "sha256:51c6635429c77cf1ae634c997ff9e53ca3438b495f10a55ba28594dd69764a8b" + "sha256:7b30a78db2922d78a6f47fb30683156a14f3c6aa5cc23f77cc8967e9ab2d002f", + "sha256:ed5157fef23a4bc4594615a0dd8eba94b2bb36bf2a343fa3d8bb2fa0a62a99d5" ], "markers": "python_version < '3.8'", - "version": "==4.6.3" + "version": "==4.6.4" }, "mccabe": { "hashes": [ diff --git a/bothub_nlp_api/app.py b/bothub_nlp_api/app.py index 7086778..fec480f 100644 --- a/bothub_nlp_api/app.py +++ b/bothub_nlp_api/app.py @@ -18,7 +18,7 @@ dsn=settings.BOTHUB_NLP_SENTRY, environment=settings.ENVIRONMENT ) # pragma: no cover -app = FastAPI(title="Bothub NLP", version="3.1.1", description="", docs_url="/") +app = FastAPI(title="Bothub NLP", version="3.1.2", description="", docs_url="/") app.include_router(v1.router, tags=["v1"]) diff --git a/bothub_nlp_api/routers/v2.py b/bothub_nlp_api/routers/v2.py index 59a604d..fcd5e8f 100644 --- a/bothub_nlp_api/routers/v2.py +++ b/bothub_nlp_api/routers/v2.py @@ -1,5 +1,6 @@ from fastapi import Depends, APIRouter, Header, HTTPException from starlette.requests import Request +from bothub_nlp_api import settings from bothub_nlp_api.exceptions.question_answering_exceptions import ( QuestionAnsweringException, @@ -226,18 +227,19 @@ async def task_queue_handler(id_task: str, from_queue: str): return task_queue.task_queue_handler(id_task, from_queue) -@router.post(r"/question-answering/?", response_model=QuestionAnsweringResponse) -async def question_answering_handler( - item: QuestionAnsweringRequest, - # authorization: str = Header(..., description="Bearer your_key"), -): - try: - result = question_answering.qa_handler( - item.context, item.question, item.language - ) - 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 +if settings.BOTHUB_NLP_API_ENABLE_QA_ROUTE: + @router.post(r"/question-answering/?", response_model=QuestionAnsweringResponse) + async def question_answering_handler( + item: QuestionAnsweringRequest, + # authorization: str = Header(..., description="Bearer your_key"), + ): + try: + result = question_answering.qa_handler( + item.context, item.question, item.language + ) + 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 diff --git a/bothub_nlp_api/settings.py b/bothub_nlp_api/settings.py index 8c5bb4c..1fe7758 100644 --- a/bothub_nlp_api/settings.py +++ b/bothub_nlp_api/settings.py @@ -39,6 +39,7 @@ def cast_supported_languages(i): BOTHUB_NLP_AWS_ACCESS_KEY_ID=(str, None), BOTHUB_NLP_AWS_SECRET_ACCESS_KEY=(str, None), BOTHUB_NLP_AWS_REGION_NAME=(str, None), + BOTHUB_NLP_API_ENABLE_QA_ROUTE=(bool, False), ) ENVIRONMENT = env.str("ENVIRONMENT") @@ -48,6 +49,8 @@ def cast_supported_languages(i): BOTHUB_NLP_API_WORKERS_PER_CORE = env.float("BOTHUB_NLP_API_WORKERS_PER_CORE") BOTHUB_NLP_API_LOG_LEVEL = env.str("BOTHUB_NLP_API_LOG_LEVEL") BOTHUB_NLP_API_KEEPALIVE = env.int("BOTHUB_NLP_API_KEEPALIVE") +# QA Route prototype activation +BOTHUB_NLP_API_ENABLE_QA_ROUTE = env.bool("BOTHUB_NLP_API_ENABLE_QA_ROUTE") # Sentry