-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from bothub-it/staging
Staging
- Loading branch information
Showing
13 changed files
with
313 additions
and
118 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
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
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,59 @@ | ||
from bothub_nlp_celery.actions import ACTION_INTENT_SENTENCE_SUGGESTION, queue_name | ||
from bothub_nlp_celery.app import celery_app | ||
from bothub_nlp_celery.tasks import TASK_NLU_INTENT_SENTENCE_SUGGESTION_TEXT | ||
from bothub_nlp_api.utils import get_repository_authorization | ||
from bothub_nlp_api.utils import backend | ||
from bothub_nlp_api import settings | ||
from bothub_nlp_api.utils import ValidationError | ||
from bothub_nlp_api.utils import AuthorizationIsRequired | ||
|
||
|
||
def _intent_sentence_suggestion( | ||
authorization, | ||
language, | ||
intent, | ||
n_sentences_to_generate, | ||
percentage_to_replace, | ||
repository_version=None, | ||
): | ||
print(authorization) | ||
from ..utils import DEFAULT_LANGS_PRIORITY | ||
|
||
if language and ( | ||
language not in settings.SUPPORTED_LANGUAGES.keys() | ||
and language not in DEFAULT_LANGS_PRIORITY.keys() | ||
): | ||
raise ValidationError("Language '{}' not supported by now.".format(language)) | ||
|
||
repository_authorization = get_repository_authorization(authorization) | ||
if not repository_authorization: | ||
raise AuthorizationIsRequired() | ||
|
||
try: | ||
update = backend().request_backend_parse( | ||
repository_authorization, language, repository_version | ||
) | ||
except Exception: | ||
update = {} | ||
answer_task = celery_app.send_task( | ||
TASK_NLU_INTENT_SENTENCE_SUGGESTION_TEXT, | ||
args=[ | ||
update.get("repository_version"), | ||
repository_authorization, | ||
intent, | ||
percentage_to_replace, | ||
n_sentences_to_generate, | ||
], | ||
queue=queue_name(language, ACTION_INTENT_SENTENCE_SUGGESTION, "SPACY"), | ||
) | ||
answer_task.wait() | ||
answer = answer_task.result | ||
answer.update( | ||
{ | ||
"language": language, | ||
"n_sentences_to_generate": n_sentences_to_generate, | ||
"percentage_to_replace": percentage_to_replace, | ||
"intent": intent, | ||
} | ||
) | ||
return answer |
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,32 @@ | ||
from bothub_nlp_celery.actions import ACTION_SCORE_CALCULATION, queue_name | ||
|
||
from ..utils import backend, get_repository_authorization | ||
from ..utils import AuthorizationIsRequired | ||
|
||
|
||
from bothub_nlp_celery.app import celery_app | ||
from bothub_nlp_celery.tasks import TASK_NLU_SCORE_CALCULATION | ||
|
||
|
||
def score_handler(authorization, repository_version, language): | ||
|
||
repository_authorization = get_repository_authorization(authorization) | ||
|
||
if not repository_authorization: | ||
raise AuthorizationIsRequired() | ||
|
||
try: | ||
update = backend().request_backend_train( | ||
repository_authorization, language, repository_version | ||
) | ||
except Exception: | ||
update = {} | ||
|
||
answer_task = celery_app.send_task( | ||
TASK_NLU_SCORE_CALCULATION, | ||
args=[update.get("current_version_id"), repository_authorization], | ||
queue=queue_name(language, ACTION_SCORE_CALCULATION), | ||
) | ||
answer_task.wait() | ||
|
||
return answer_task.result |
Oops, something went wrong.