Skip to content

Commit

Permalink
Merge pull request #659 from Ilhasoft/hotfix/update_available_languages
Browse files Browse the repository at this point in the history
update available_languages in repository to return the languages of t…
  • Loading branch information
helllllllder committed Oct 25, 2021
2 parents 168cd7e + 63590ea commit 3ed6f57
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ You can set environment variables in your OS, write on ```.env``` file or pass v
| RECAPTCHA_SECRET_KEY | ```string``` | ```''``` | Token of the recaptcha used in the validation of a user's registration.
| REPOSITORY_NLP_LOG_LIMIT | ```int``` | ```10000``` | Limit of query size to repository log.
| REPOSITORY_RESTRICT_ACCESS_NLP_LOGS | ```list``` | ```[]``` | Restricts log access to a particular or multiple intelligences
| REPOSITORY_KNOWLEDGE_BASE_DESCRIPTION_LIMIT | ```int``` | ```450``` | Limit of characters in the knowledge base description
| ELASTICSEARCH_DSL | ```string``` | ```es:9200``` | URL Elasticsearch.
| ELASTICSEARCH_NUMBER_OF_SHARDS | ```int``` | ```1``` | Specify the number of shards for the indexes.
| ELASTICSEARCH_NUMBER_OF_REPLICAS | ```int``` | ```1``` | Specify the number of replicas for the indexes.
Expand Down
3 changes: 2 additions & 1 deletion bothub/api/v2/tests/test_knowledge_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from django.conf import settings
from django.test import TestCase
from django.test import RequestFactory
from rest_framework import status
Expand Down Expand Up @@ -240,7 +241,7 @@ def test_okay(self):
response, content_data = self.request(self.repository, self.owner_token)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(content_data.get("title"), self.knowledge_base_1.title)
self.assertEqual(content_data.get("description"), self.context_1.text[:150])
self.assertEqual(content_data.get("description"), self.context_1.text[:settings.REPOSITORY_KNOWLEDGE_BASE_DESCRIPTION_LIMIT])


class ListQAtextAPITestCase(DefaultSetUpKnowledgeBaseMixin, TestCase):
Expand Down
43 changes: 24 additions & 19 deletions bothub/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,24 +580,29 @@ def request_nlp_qa(self, user_authorization, data):
)

def available_languages(self, language=None, queryset=None, version_default=True):
examples = self.examples(
language=language, queryset=queryset, version_default=version_default
)
examples_languages = examples.values_list(
"repository_version_language__language", flat=True
)
translations_languages = (
examples.annotate(translations_count=models.Count("translations"))
.filter(translations_count__gt=0)
.values_list("translations__language", flat=True)
)
return list(
set(
[self.language]
+ list(set(examples_languages))
+ list(set(translations_languages))
if self.repository_type != self.TYPE_CONTENT:
examples = self.examples(
language=language, queryset=queryset, version_default=version_default
)
)
examples_languages = examples.values_list(
"repository_version_language__language", flat=True
)
translations_languages = (
examples.annotate(translations_count=models.Count("translations"))
.filter(translations_count__gt=0)
.values_list("translations__language", flat=True)
)
return list(
set(
[self.language]
+ list(set(examples_languages))
+ list(set(translations_languages))
)
)
else:
knowledge_bases_languages = list(set(self.knowledge_bases.values_list("texts__language", flat=True)))
knowledge_bases_languages.remove(None)
return knowledge_bases_languages

@property
def languages_status(self):
Expand Down Expand Up @@ -2311,9 +2316,9 @@ def get_languages_count(self):
def get_text_description(self, lang=None):
try:
if not lang:
return self.texts.first().text[:150]
return self.texts.first().text[:settings.REPOSITORY_KNOWLEDGE_BASE_DESCRIPTION_LIMIT]
else:
return get_object_or_404(self.texts.all(), language=lang).text[:150]
return get_object_or_404(self.texts.all(), language=lang).text[:settings.REPOSITORY_KNOWLEDGE_BASE_DESCRIPTION_LIMIT]
except AttributeError:
return ""

Expand Down
4 changes: 4 additions & 0 deletions bothub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
CONNECT_GRPC_SERVER_URL=(str, "localhost:8002"),
CONNECT_CERTIFICATE_GRPC_CRT=(str, None),
REPOSITORY_RESTRICT_ACCESS_NLP_LOGS=(list, []),
REPOSITORY_KNOWLEDGE_BASE_DESCRIPTION_LIMIT=(int, 450),
ELASTICSEARCH_DSL=(str, "localhost:9200"),
ELASTICSEARCH_REPOSITORYNLPLOG_INDEX=(str, "ai_repositorynlplog"),
ELASTICSEARCH_REPOSITORYQANLPLOG_INDEX=(str, "ai_repositoryqanlplog"),
Expand Down Expand Up @@ -441,6 +442,9 @@
# Restrict access to the nlp logs by a list of repository uuids
REPOSITORY_RESTRICT_ACCESS_NLP_LOGS = env.list("REPOSITORY_RESTRICT_ACCESS_NLP_LOGS")

# Limit of characters for the knowledge base description
REPOSITORY_KNOWLEDGE_BASE_DESCRIPTION_LIMIT = env.list("REPOSITORY_KNOWLEDGE_BASE_DESCRIPTION_LIMIT", default=450)


# django_redis
CACHES = {
Expand Down

0 comments on commit 3ed6f57

Please sign in to comment.