Skip to content

Commit 0ae8d5d

Browse files
committed
Merge branch 'develop'
2 parents 0e53feb + c4c3a11 commit 0ae8d5d

File tree

27 files changed

+998
-402
lines changed

27 files changed

+998
-402
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Bothub NLP - Natural Language Processing services
22

3-
![version 2.1.1](https://img.shields.io/badge/version-2.1.1-blue.svg) [![python 3.6](https://img.shields.io/badge/python-3.6-green.svg)](https://docs.python.org/3.6/whatsnew/changelog.html) [![license AGPL-3.0](https://img.shields.io/badge/license-AGPL--3.0-red.svg)](https://github.com/udomobi/bothub-nlp/blob/master/LICENSE)
3+
![version 2.2.0](https://img.shields.io/badge/version-2.2.0-blue.svg) [![python 3.6](https://img.shields.io/badge/python-3.6-green.svg)](https://docs.python.org/3.6/whatsnew/changelog.html) [![license AGPL-3.0](https://img.shields.io/badge/license-AGPL--3.0-red.svg)](https://github.com/udomobi/bothub-nlp/blob/master/LICENSE)
44

55
Check the [main Bothub project repository](https://github.com/Ilhasoft/bothub).
66

bothub-nlp-api/Pipfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ lint = "flake8"
1010
[packages]
1111
tornado = "==5.1.1"
1212
raven = "*"
13-
bothub-engine = {ref = "1.19.1", git = "https://github.com/Ilhasoft/bothub-engine"}
13+
bothub-engine = {ref = "1.21.0", git = "https://github.com/Ilhasoft/bothub-engine"}
1414
bothub-nlp-celery = {path = "./../bothub-nlp-celery"}
1515
python-decouple = "*"
1616
bothub-nlp = {path = "./../bothub-nlp"}

bothub-nlp-api/Pipfile.lock

+40-42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bothub-nlp-api/bothub_nlp_api/app.py

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .handlers.parse import ParseHandler
1212
from .handlers.train import TrainHandler
1313
from .handlers.info import InfoHandler
14+
from .handlers.evaluate import EvaluateHandler
1415

1516

1617
app = None
@@ -24,6 +25,7 @@ def make_app():
2425
url('/parse/', ParseHandler),
2526
url('/train/', TrainHandler),
2627
url('/info/', InfoHandler),
28+
url('/evaluate/', EvaluateHandler)
2729
])
2830

2931

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import tornado.web
2+
from tornado import gen
3+
4+
from bothub_nlp_celery.actions import ACTION_EVALUATE, queue_name
5+
from bothub_nlp_celery.tasks import TASK_NLU_EVALUATE_UPDATE
6+
from bothub_nlp_celery.app import celery_app
7+
from bothub_nlp import settings as bothub_nlp_settings
8+
9+
from . import ApiHandler
10+
from ..utils import ValidationError
11+
from ..utils import authorization_required
12+
from ..utils import AuthorizationIsRequired
13+
from ..utils import NEXT_LANGS
14+
15+
16+
EVALUATE_STATUS_EVALUATED = 'evaluated'
17+
EVALUATE_STATUS_FAILED = 'failed'
18+
19+
20+
class EvaluateHandler(ApiHandler):
21+
@tornado.web.asynchronous
22+
@gen.engine
23+
@authorization_required
24+
def post(self):
25+
language = self.get_argument('language', default=None)
26+
27+
if language and (
28+
language not in bothub_nlp_settings.SUPPORTED_LANGUAGES.keys() and
29+
language not in NEXT_LANGS.keys()
30+
):
31+
raise ValidationError(
32+
'Language \'{}\' not supported by now.'.format(language),
33+
field='language')
34+
35+
repository_authorization = self.repository_authorization()
36+
if not repository_authorization:
37+
raise AuthorizationIsRequired()
38+
39+
repository = repository_authorization.repository
40+
update = repository.last_trained_update(language)
41+
42+
if not update:
43+
raise ValidationError(
44+
'This repository has never been trained',
45+
field='language')
46+
47+
try:
48+
evaluate_task = celery_app.send_task(
49+
TASK_NLU_EVALUATE_UPDATE,
50+
args=[
51+
update.id,
52+
repository_authorization.user.id,
53+
],
54+
queue=queue_name(ACTION_EVALUATE, update.language))
55+
evaluate_task.wait()
56+
evaluate = evaluate_task.result
57+
evaluate_report = {
58+
'language': language,
59+
'status': EVALUATE_STATUS_EVALUATED,
60+
'update_id': update.id,
61+
'evaluate_id': evaluate.get('id'),
62+
'evaluate_version': evaluate.get('version'),
63+
}
64+
except Exception as e:
65+
from .. import logger
66+
logger.exception(e)
67+
68+
evaluate_report = {
69+
'status': EVALUATE_STATUS_FAILED,
70+
'error': str(e),
71+
}
72+
73+
self.finish(evaluate_report)

bothub-nlp-celery/bothub_nlp_celery/actions.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
ACTION_PARSE = 'parse'
55
ACTION_TRAIN = 'train'
6+
ACTION_EVALUATE = 'evaluate'
67

78

89
def queue_name(action, language):

bothub-nlp-celery/bothub_nlp_celery/app.py

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from .actions import ACTION_PARSE
66
from .actions import ACTION_TRAIN
7+
from .actions import ACTION_EVALUATE
78
from .actions import queue_name
89
from . import settings
910

@@ -19,6 +20,9 @@
1920
] + [
2021
queue_name(ACTION_TRAIN, lang)
2122
for lang in bothub_nlp_settings.SUPPORTED_LANGUAGES.keys()
23+
] + [
24+
queue_name(ACTION_EVALUATE, lang)
25+
for lang in bothub_nlp_settings.SUPPORTED_LANGUAGES.keys()
2226
])
2327
celery_app.conf.task_queues = [
2428
Queue(queue)
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
TASK_NLU_PARSE_TEXT = 'nlu-parse-text'
22
TASK_NLU_TRAIN_UPDATE = 'nlu-train-update'
3+
TASK_NLU_EVALUATE_UPDATE = 'nlu-evaluate-update'

bothub-nlp-nlu-worker-on-demand/Pipfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ celery-worker-on-demand = {ref = "0.2.0", git = "https://github.com/Ilhasoft/cel
1313
bothub-nlp-celery = {path = "./../bothub-nlp-celery"}
1414
docker = "==3.7.0"
1515
bothub-nlp = {path = "./../bothub-nlp"}
16-
bothub-engine = {ref = "1.19.1", git = "https://github.com/Ilhasoft/bothub-engine"}
16+
bothub-engine = {ref = "1.21.0", git = "https://github.com/Ilhasoft/bothub-engine"}
1717

1818
[dev-packages]
1919
redis = "*"

bothub-nlp-nlu-worker-on-demand/Pipfile.lock

+23-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bothub-nlp-nlu-worker-on-demand/bothub_nlp_nlu_worker_on_demand/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
'BOTHUB_NLP_CELERY_BROKER_URL',
4848
'BOTHUB_NLP_CELERY_BACKEND_URL',
4949
'BOTHUB_NLP_NLU_AGROUP_LANGUAGE_QUEUE',
50+
'BOTHUB_NLP_AWS_S3_BUCKET_NAME',
51+
'BOTHUB_NLP_AWS_ACCESS_KEY_ID',
52+
'BOTHUB_NLP_AWS_SECRET_ACCESS_KEY',
5053
]
5154
]
5255

0 commit comments

Comments
 (0)