Skip to content

Commit

Permalink
Merge branch 'develop' into analyze-rasa-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Paz committed Oct 23, 2018
2 parents 1df029b + 8e0d3f4 commit 7b8f963
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 9 deletions.
1 change: 1 addition & 0 deletions bothub/api/serializers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Meta:
'ready_for_train',
'requirements_to_train',
'languages_ready_for_train',
'languages_warnings',
'votes_sum',
'created_at',
]
Expand Down
3 changes: 3 additions & 0 deletions bothub/common/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class RepositoryUpdateInline(admin.TabularInline):

fields = [
'language',
'use_language_model_featurizer',
'use_competing_intents',
'created_at',
'by',
'training_started_at',
Expand All @@ -21,6 +23,7 @@ class RepositoryUpdateInline(admin.TabularInline):
'training_log',
'download_bot_data',
]
readonly_fields = fields

def download_bot_data(self, obj):
if not obj.trained_at:
Expand Down
26 changes: 23 additions & 3 deletions bothub/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ def ready_for_train(self):
self.current_updates,
False)

@property
def languages_warnings(self):
return dict(filter(
lambda w: len(w[1]) > 0,
map(
lambda u: (u.language, u.warnings,),
self.current_updates)))

@property
def votes_sum(self):
return self.votes.aggregate(
Expand Down Expand Up @@ -314,9 +322,7 @@ def current_update(self, language=None):
language = language or self.language
repository_update, created = self.updates.get_or_create(
language=language,
training_started_at=None,
use_language_model_featurizer=self.use_language_model_featurizer,
use_competing_intents=self.use_competing_intents)
training_started_at=None)
return repository_update

def last_trained_update(self, language=None):
Expand Down Expand Up @@ -349,6 +355,7 @@ class Meta:

MIN_EXAMPLES_PER_INTENT = 2
MIN_EXAMPLES_PER_ENTITY = 2
RECOMMENDED_INTENTS = 2

repository = models.ForeignKey(
Repository,
Expand Down Expand Up @@ -479,6 +486,19 @@ def ready_for_train(self):
return True
return len(self.requirements_to_train) is 0

@property
def intents(self):
return list(set(self.examples.values_list('intent', flat=True)))

@property
def warnings(self):
w = []
if 0 < len(self.intents) < self.RECOMMENDED_INTENTS:
w.append(_('You need to have at least {} intents for the ' +
'algorithm to identify intents.').format(
self.RECOMMENDED_INTENTS))
return w

def __str__(self):
return 'Repository Update #{}'.format(self.id)

Expand Down
33 changes: 31 additions & 2 deletions bothub/common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,6 @@ def test_equal_repository_value_after_train(self):
current_update = self.repository.current_update()
self.repository.use_language_model_featurizer = False
self.repository.save()
self.assertTrue(current_update.use_language_model_featurizer)
current_update.start_training(self.owner)
current_update.save_training(b'')
self.assertFalse(current_update.use_language_model_featurizer)
Expand Down Expand Up @@ -1137,7 +1136,37 @@ def test_equal_repository_value_after_train(self):
current_update = self.repository.current_update()
self.repository.use_competing_intents = False
self.repository.save()
self.assertTrue(current_update.use_competing_intents)
current_update.start_training(self.owner)
current_update.save_training(b'')
self.assertFalse(current_update.use_competing_intents)


class RepositoryUpdateWarnings(TestCase):
def setUp(self):
self.language = languages.LANGUAGE_EN

self.owner = User.objects.create_user('owner@user.com', 'user')

self.repository = Repository.objects.create(
owner=self.owner,
name='Test',
slug='test',
language=self.language,
use_competing_intents=True)

RepositoryExample.objects.create(
repository_update=self.repository.current_update(),
text='my name is Douglas',
intent='greet')

def test_min_intents(self):
self.assertEqual(
len(self.repository.current_update().warnings),
1)
RepositoryExample.objects.create(
repository_update=self.repository.current_update(),
text='bye',
intent='bye')
self.assertEqual(
len(self.repository.current_update().warnings),
0)
4 changes: 2 additions & 2 deletions bothub/health/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def check_database_connection(**kwargs):

def check_accessible_api(request, **kwargs):
import requests
logger.info('requesting {}'.format(CHECK_ACCESSIBLE_API_URL))
if CHECK_ACCESSIBLE_API_URL:
logger.info('requesting {}'.format(CHECK_ACCESSIBLE_API_URL))
response = requests.get(CHECK_ACCESSIBLE_API_URL)
else:
url = 'http://{}/api/repositories/'.format(
url = 'http://{}/200/'.format(
request.META.get('HTTP_HOST'))
logger.info('requesting to {}'.format(url))
response = requests.get(url)
Expand Down
1 change: 0 additions & 1 deletion bothub/health/tests.py

This file was deleted.

4 changes: 4 additions & 0 deletions bothub/health/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ def ping(request):
content=content,
content_type='text/plain',
status=status_code)


def r200(request):
return HttpResponse()
2 changes: 2 additions & 0 deletions bothub/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from bothub.api.routers import router as bothub_api_routers
from bothub.health.views import ping
from bothub.health.views import r200
from bothub.common.views import download_bot_data


Expand All @@ -14,6 +15,7 @@
path('docs/', include_docs_urls(title='API Documentation')),
path('admin/', admin.site.urls),
path('ping/', ping, name='ping'),
path('200/', r200, name='200'),
path(
'downloadbotdata/<int:update_id>/',
download_bot_data,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='bothub-engine',
version='1.16.0',
version='1.16.1',
description='Bothub Engine',
packages=find_packages(),
install_requires=[
Expand Down

0 comments on commit 7b8f963

Please sign in to comment.