Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Train language API #584

Merged
merged 3 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ exclude =
./bothub/common/migrations
./manage.py
./bothub/common/languages.py
./bothub/protos/
55 changes: 53 additions & 2 deletions bothub/api/v2/nlp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ def retrieve(self, request, *args, **kwargs):

repository_version = request.query_params.get("repository_version")
if repository_version:
current_version = repository_authorization.repository.get_specific_version_id(
repository_version, str(request.query_params.get("language"))
current_version = (
repository_authorization.repository.get_specific_version_id(
repository_version, str(request.query_params.get("language"))
)
)
else:
current_version = repository_authorization.repository.current_version(
Expand Down Expand Up @@ -193,6 +195,55 @@ def training_log(self, request, **kwargs):
return Response({})


class RepositoryAuthorizationTrainLanguagesViewSet(
mixins.RetrieveModelMixin, GenericViewSet
):
queryset = RepositoryAuthorization.objects
serializer_class = NLPSerializer
permission_classes = [AllowAny]
pagination_class = NLPPagination
authentication_classes = [NLPAuthentication]

def retrieve(self, request, *args, **kwargs):
check_auth(request)
repository_authorization = self.get_object()

if not repository_authorization.can_contribute:
raise PermissionDenied()

repository_version = request.query_params.get("repository_version")

response = []

for language in settings.SUPPORTED_LANGUAGES:

if repository_version:
current_version = (
repository_authorization.repository.get_specific_version_id(
repository_version, language
)
)
else:
current_version = repository_authorization.repository.current_version(
language
)

if current_version.ready_for_train:
response.append(
{
"current_version_id": current_version.id,
"repository_authorization_user_id": repository_authorization.user.id,
"language": current_version.language,
"algorithm": current_version.repository_version.repository.algorithm,
"use_name_entities": current_version.repository_version.repository.use_name_entities,
"use_competing_intents": current_version.repository_version.repository.use_competing_intents,
"use_analyze_char": current_version.repository_version.repository.use_analyze_char,
}
)

return Response(response)


class RepositoryAuthorizationParseViewSet(mixins.RetrieveModelMixin, GenericViewSet):
queryset = RepositoryAuthorization.objects
serializer_class = NLPSerializer
Expand Down
9 changes: 8 additions & 1 deletion bothub/api/v2/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
from .repository.views import RepositoryAuthorizationViewSet
from .repository.views import RepositoryAuthorizationRequestsViewSet
from .repository.views import RepositoryExampleViewSet
from .nlp.views import RepositoryAuthorizationTrainViewSet, RepositoryNLPLogsViewSet
from .nlp.views import (
RepositoryAuthorizationTrainViewSet,
RepositoryNLPLogsViewSet,
RepositoryAuthorizationTrainLanguagesViewSet,
)
from .nlp.views import RepositoryAuthorizationParseViewSet
from .nlp.views import RepositoryAuthorizationInfoViewSet
from .nlp.views import RepositoryAuthorizationEvaluateViewSet
Expand Down Expand Up @@ -170,6 +174,9 @@ def get_lookup_regex(self, viewset, lookup_prefix=""):
router.register(
"repository/nlp/authorization/train", RepositoryAuthorizationTrainViewSet
)
router.register(
"repository/nlp/authorization/train-languages", RepositoryAuthorizationTrainLanguagesViewSet
)
router.register(
"repository/nlp/authorization/parse", RepositoryAuthorizationParseViewSet
)
Expand Down
2 changes: 1 addition & 1 deletion bothub/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
schema_view = get_schema_view(
openapi.Info(
title="API Documentation",
default_version="v2.1.18",
default_version="v2.1.22",
description="Documentation",
terms_of_service="https://bothub.it/terms",
contact=openapi.Contact(email="bothub@ilhasoft.com.br"),
Expand Down