Skip to content

Commit

Permalink
Merge pull request #107 from bothub-it/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
lucasagra authored Aug 18, 2021
2 parents b826410 + 8bbcd9d commit 6787829
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 32 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
39 changes: 23 additions & 16 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bothub_nlp_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
32 changes: 17 additions & 15 deletions bothub_nlp_api/routers/v2.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions bothub_nlp_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

Expand Down

0 comments on commit 6787829

Please sign in to comment.