-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
998 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import tornado.web | ||
from tornado import gen | ||
|
||
from bothub_nlp_celery.actions import ACTION_EVALUATE, queue_name | ||
from bothub_nlp_celery.tasks import TASK_NLU_EVALUATE_UPDATE | ||
from bothub_nlp_celery.app import celery_app | ||
from bothub_nlp import settings as bothub_nlp_settings | ||
|
||
from . import ApiHandler | ||
from ..utils import ValidationError | ||
from ..utils import authorization_required | ||
from ..utils import AuthorizationIsRequired | ||
from ..utils import NEXT_LANGS | ||
|
||
|
||
EVALUATE_STATUS_EVALUATED = 'evaluated' | ||
EVALUATE_STATUS_FAILED = 'failed' | ||
|
||
|
||
class EvaluateHandler(ApiHandler): | ||
@tornado.web.asynchronous | ||
@gen.engine | ||
@authorization_required | ||
def post(self): | ||
language = self.get_argument('language', default=None) | ||
|
||
if language and ( | ||
language not in bothub_nlp_settings.SUPPORTED_LANGUAGES.keys() and | ||
language not in NEXT_LANGS.keys() | ||
): | ||
raise ValidationError( | ||
'Language \'{}\' not supported by now.'.format(language), | ||
field='language') | ||
|
||
repository_authorization = self.repository_authorization() | ||
if not repository_authorization: | ||
raise AuthorizationIsRequired() | ||
|
||
repository = repository_authorization.repository | ||
update = repository.last_trained_update(language) | ||
|
||
if not update: | ||
raise ValidationError( | ||
'This repository has never been trained', | ||
field='language') | ||
|
||
try: | ||
evaluate_task = celery_app.send_task( | ||
TASK_NLU_EVALUATE_UPDATE, | ||
args=[ | ||
update.id, | ||
repository_authorization.user.id, | ||
], | ||
queue=queue_name(ACTION_EVALUATE, update.language)) | ||
evaluate_task.wait() | ||
evaluate = evaluate_task.result | ||
evaluate_report = { | ||
'language': language, | ||
'status': EVALUATE_STATUS_EVALUATED, | ||
'update_id': update.id, | ||
'evaluate_id': evaluate.get('id'), | ||
'evaluate_version': evaluate.get('version'), | ||
} | ||
except Exception as e: | ||
from .. import logger | ||
logger.exception(e) | ||
|
||
evaluate_report = { | ||
'status': EVALUATE_STATUS_FAILED, | ||
'error': str(e), | ||
} | ||
|
||
self.finish(evaluate_report) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
TASK_NLU_PARSE_TEXT = 'nlu-parse-text' | ||
TASK_NLU_TRAIN_UPDATE = 'nlu-train-update' | ||
TASK_NLU_EVALUATE_UPDATE = 'nlu-evaluate-update' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.