We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Disallow samples without intent or entities
Disallow samples creation without an intent or one entity at least.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `bothub/api/validators.py`
Content:
```
1 from django.utils.translation import gettext as _
2 from rest_framework.exceptions import PermissionDenied
3 from rest_framework.exceptions import ValidationError
4 
5 from bothub.common.models import RepositoryTranslatedExample
6 
7 
8 class CanContributeInRepositoryValidator(object):
9     def __call__(self, value):
10         user_authorization = value.get_user_authorization(
11             self.request.user)
12         if not user_authorization.can_contribute:
13             raise PermissionDenied(
14                 _('You can\'t contribute in this repository'))
15 
16     def set_context(self, serializer):
17         self.request = serializer.context.get('request')
18 
19 
20 class CanContributeInRepositoryExampleValidator(object):
21     def __call__(self, value):
22         repository = value.repository_update.repository
23         user_authorization = repository.get_user_authorization(
24             self.request.user)
25         if not user_authorization.can_contribute:
26             raise PermissionDenied(
27                 _('You can\'t contribute in this repository'))
28 
29     def set_context(self, serializer):
30         self.request = serializer.context.get('request')
31 
32 
33 class CanContributeInRepositoryTranslatedExampleValidator(object):
34     def __call__(self, value):
35         repository = value.original_example.repository_update.repository
36         user_authorization = repository.get_user_authorization(
37             self.request.user)
38         if not user_authorization.can_contribute:
39             raise PermissionDenied(
40                 _('You can\'t contribute in this repository'))
41 
42     def set_context(self, serializer):
43         self.request = serializer.context.get('request')
44 
45 
46 class TranslatedExampleEntitiesValidator(object):
47     def __call__(self, attrs):
48         original_example = attrs.get('original_example')
49         entities_valid = RepositoryTranslatedExample.same_entities_validator(
50             list(map(lambda x: dict(x), attrs.get('entities'))),
51             list(map(lambda x: x.to_dict, original_example.entities.all())))
52         if not entities_valid:
53             raise ValidationError({'entities': _('Invalid entities')})
54 
55 
56 class TranslatedExampleLanguageValidator(object):
57     def __call__(self, attrs):
58         original_example = attrs.get('original_example')
59         language = attrs.get('language')
60         if original_example.repository_update.language == language:
61             raise ValidationError({'language': _(
62                 'Can\'t translate to the same language')})
63
```

Path: `bothub/api/serializers/example.py`
Content:
```
1 from rest_framework import serializers
2 
3 from django.utils.translation import gettext as _
4 
5 from bothub.common.models import Repository
6 from bothub.common.models import RepositoryExample
7 from bothub.common.models import RepositoryExampleEntity
8 
9 from ..fields import EntityText
10 from ..validators import CanContributeInRepositoryExampleValidator
11 from ..validators import CanContributeInRepositoryValidator
12 from .translate import RepositoryTranslatedExampleSerializer
13 
14 
15 class RepositoryExampleEntitySerializer(serializers.ModelSerializer):
16     class Meta:
17         model = RepositoryExampleEntity
18         fields = [
19             'id',
20             'repository_example',
21             'start',
22             'end',
23             'entity',
24             'created_at',
25             'value',
26         ]
27 
28     repository_example = serializers.PrimaryKeyRelatedField(
29         queryset=RepositoryExample.objects,
30         validators=[
31             CanContributeInRepositoryExampleValidator(),
32         ],
33         help_text=_('Example\'s ID'))
34     value = serializers.SerializerMethodField()
35 
36     def get_value(self, obj):
37         return obj.value
38 
39 
40 class NewRepositoryExampleEntitySerializer(serializers.ModelSerializer):
41     class Meta:
42         model = RepositoryExampleEntity
43         fields = [
44             'repository_example',
45             'start',
46             'end',
47             'entity',
48         ]
49 
50 
51 class RepositoryExampleSerializer(serializers.ModelSerializer):
52     class Meta:
53         model = RepositoryExample
54         fields = [
55             'id',
56             'repository_update',
57             'deleted_in',
58             'text',
59             'intent',
60             'language',
61             'created_at',
62             'entities',
63             'translations',
64         ]
65         read_only_fields = [
66             'repository_update',
67             'deleted_in',
68         ]
69 
70     entities = RepositoryExampleEntitySerializer(
71         many=True,
72         read_only=True)
73     translations = RepositoryTranslatedExampleSerializer(
74         many=True,
75         read_only=True)
76     language = serializers.SerializerMethodField()
77 
78     def get_language(self, obj):
79         return obj.language
80 
81 
82 class NewRepositoryExampleSerializer(serializers.ModelSerializer):
83     class Meta:
84         model = RepositoryExample
85         fields = [
86             'id',
87             'repository',
88             'repository_update',
89             'text',
90             'entities',
91             'intent',
92         ]
93 
94     id = serializers.PrimaryKeyRelatedField(
95         read_only=True,
96         style={'show': False})
97     text = EntityText(style={'entities_field': 'entities'})
98     repository = serializers.PrimaryKeyRelatedField(
99         queryset=Repository.objects,
100         validators=[
101             CanContributeInRepositoryValidator(),
102         ],
103         source='repository_update',
104         style={'show': False})
105     repository_update = serializers.PrimaryKeyRelatedField(
106         read_only=True,
107         style={'show': False})
108     entities = NewRepositoryExampleEntitySerializer(
109         many=True,
110         style={'text_field': 'text'})
111 
112     def validate_repository(self, repository):
113         return repository.current_update()
114 
115     def create(self, validated_data):
116         entities_data = validated_data.pop('entities')
117         example = self.Meta.model.objects.create(**validated_data)
118         for entity_data in entities_data:
119             RepositoryExampleEntity.objects.create(
120                 repository_example=example,
121                 **entity_data)
122         return example
123
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/bothub/api/serializers/example.py b/bothub/api/serializers/example.py
--- a/bothub/api/serializers/example.py
+++ b/bothub/api/serializers/example.py
@@ -9,6 +9,7 @@
 from ..fields import EntityText
 from ..validators import CanContributeInRepositoryExampleValidator
 from ..validators import CanContributeInRepositoryValidator
+from ..validators import ExampleWithIntentOrEntityValidator
 from .translate import RepositoryTranslatedExampleSerializer
 
 
@@ -109,6 +110,10 @@
         many=True,
         style={'text_field': 'text'})
 
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.validators.append(ExampleWithIntentOrEntityValidator())
+
     def validate_repository(self, repository):
         return repository.current_update()
 
diff --git a/bothub/api/validators.py b/bothub/api/validators.py
--- a/bothub/api/validators.py
+++ b/bothub/api/validators.py
@@ -60,3 +60,12 @@
         if original_example.repository_update.language == language:
             raise ValidationError({'language': _(
                 'Can\'t translate to the same language')})
+
+
+class ExampleWithIntentOrEntityValidator(object):
+    def __call__(self, attrs):
+        intent = attrs.get('intent')
+        entities = attrs.get('entities')
+
+        if not intent and not entities:
+            raise ValidationError(_('Define a intent or one entity'))

{"golden_diff": "diff --git a/bothub/api/serializers/example.py b/bothub/api/serializers/example.py\n--- a/bothub/api/serializers/example.py\n+++ b/bothub/api/serializers/example.py\n@@ -9,6 +9,7 @@\n from ..fields import EntityText\n from ..validators import CanContributeInRepositoryExampleValidator\n from ..validators import CanContributeInRepositoryValidator\n+from ..validators import ExampleWithIntentOrEntityValidator\n from .translate import RepositoryTranslatedExampleSerializer\n \n \n@@ -109,6 +110,10 @@\n         many=True,\n         style={'text_field': 'text'})\n \n+    def __init__(self, *args, **kwargs):\n+        super().__init__(*args, **kwargs)\n+        self.validators.append(ExampleWithIntentOrEntityValidator())\n+\n     def validate_repository(self, repository):\n         return repository.current_update()\n \ndiff --git a/bothub/api/validators.py b/bothub/api/validators.py\n--- a/bothub/api/validators.py\n+++ b/bothub/api/validators.py\n@@ -60,3 +60,12 @@\n         if original_example.repository_update.language == language:\n             raise ValidationError({'language': _(\n                 'Can\\'t translate to the same language')})\n+\n+\n+class ExampleWithIntentOrEntityValidator(object):\n+    def __call__(self, attrs):\n+        intent = attrs.get('intent')\n+        entities = attrs.get('entities')\n+\n+        if not intent and not entities:\n+            raise ValidationError(_('Define a intent or one entity'))\n", "issue": "Disallow samples without intent or entities\nDisallow samples creation without an intent or one entity at least.\n", "before_files": [{"content": "from django.utils.translation import gettext as _\nfrom rest_framework.exceptions import PermissionDenied\nfrom rest_framework.exceptions import ValidationError\n\nfrom bothub.common.models import RepositoryTranslatedExample\n\n\nclass CanContributeInRepositoryValidator(object):\n    def __call__(self, value):\n        user_authorization = value.get_user_authorization(\n            self.request.user)\n        if not user_authorization.can_contribute:\n            raise PermissionDenied(\n                _('You can\\'t contribute in this repository'))\n\n    def set_context(self, serializer):\n        self.request = serializer.context.get('request')\n\n\nclass CanContributeInRepositoryExampleValidator(object):\n    def __call__(self, value):\n        repository = value.repository_update.repository\n        user_authorization = repository.get_user_authorization(\n            self.request.user)\n        if not user_authorization.can_contribute:\n            raise PermissionDenied(\n                _('You can\\'t contribute in this repository'))\n\n    def set_context(self, serializer):\n        self.request = serializer.context.get('request')\n\n\nclass CanContributeInRepositoryTranslatedExampleValidator(object):\n    def __call__(self, value):\n        repository = value.original_example.repository_update.repository\n        user_authorization = repository.get_user_authorization(\n            self.request.user)\n        if not user_authorization.can_contribute:\n            raise PermissionDenied(\n                _('You can\\'t contribute in this repository'))\n\n    def set_context(self, serializer):\n        self.request = serializer.context.get('request')\n\n\nclass TranslatedExampleEntitiesValidator(object):\n    def __call__(self, attrs):\n        original_example = attrs.get('original_example')\n        entities_valid = RepositoryTranslatedExample.same_entities_validator(\n            list(map(lambda x: dict(x), attrs.get('entities'))),\n            list(map(lambda x: x.to_dict, original_example.entities.all())))\n        if not entities_valid:\n            raise ValidationError({'entities': _('Invalid entities')})\n\n\nclass TranslatedExampleLanguageValidator(object):\n    def __call__(self, attrs):\n        original_example = attrs.get('original_example')\n        language = attrs.get('language')\n        if original_example.repository_update.language == language:\n            raise ValidationError({'language': _(\n                'Can\\'t translate to the same language')})\n", "path": "bothub/api/validators.py"}, {"content": "from rest_framework import serializers\n\nfrom django.utils.translation import gettext as _\n\nfrom bothub.common.models import Repository\nfrom bothub.common.models import RepositoryExample\nfrom bothub.common.models import RepositoryExampleEntity\n\nfrom ..fields import EntityText\nfrom ..validators import CanContributeInRepositoryExampleValidator\nfrom ..validators import CanContributeInRepositoryValidator\nfrom .translate import RepositoryTranslatedExampleSerializer\n\n\nclass RepositoryExampleEntitySerializer(serializers.ModelSerializer):\n    class Meta:\n        model = RepositoryExampleEntity\n        fields = [\n            'id',\n            'repository_example',\n            'start',\n            'end',\n            'entity',\n            'created_at',\n            'value',\n        ]\n\n    repository_example = serializers.PrimaryKeyRelatedField(\n        queryset=RepositoryExample.objects,\n        validators=[\n            CanContributeInRepositoryExampleValidator(),\n        ],\n        help_text=_('Example\\'s ID'))\n    value = serializers.SerializerMethodField()\n\n    def get_value(self, obj):\n        return obj.value\n\n\nclass NewRepositoryExampleEntitySerializer(serializers.ModelSerializer):\n    class Meta:\n        model = RepositoryExampleEntity\n        fields = [\n            'repository_example',\n            'start',\n            'end',\n            'entity',\n        ]\n\n\nclass RepositoryExampleSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = RepositoryExample\n        fields = [\n            'id',\n            'repository_update',\n            'deleted_in',\n            'text',\n            'intent',\n            'language',\n            'created_at',\n            'entities',\n            'translations',\n        ]\n        read_only_fields = [\n            'repository_update',\n            'deleted_in',\n        ]\n\n    entities = RepositoryExampleEntitySerializer(\n        many=True,\n        read_only=True)\n    translations = RepositoryTranslatedExampleSerializer(\n        many=True,\n        read_only=True)\n    language = serializers.SerializerMethodField()\n\n    def get_language(self, obj):\n        return obj.language\n\n\nclass NewRepositoryExampleSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = RepositoryExample\n        fields = [\n            'id',\n            'repository',\n            'repository_update',\n            'text',\n            'entities',\n            'intent',\n        ]\n\n    id = serializers.PrimaryKeyRelatedField(\n        read_only=True,\n        style={'show': False})\n    text = EntityText(style={'entities_field': 'entities'})\n    repository = serializers.PrimaryKeyRelatedField(\n        queryset=Repository.objects,\n        validators=[\n            CanContributeInRepositoryValidator(),\n        ],\n        source='repository_update',\n        style={'show': False})\n    repository_update = serializers.PrimaryKeyRelatedField(\n        read_only=True,\n        style={'show': False})\n    entities = NewRepositoryExampleEntitySerializer(\n        many=True,\n        style={'text_field': 'text'})\n\n    def validate_repository(self, repository):\n        return repository.current_update()\n\n    def create(self, validated_data):\n        entities_data = validated_data.pop('entities')\n        example = self.Meta.model.objects.create(**validated_data)\n        for entity_data in entities_data:\n            RepositoryExampleEntity.objects.create(\n                repository_example=example,\n                **entity_data)\n        return example\n", "path": "bothub/api/serializers/example.py"}], "after_files": [{"content": "from django.utils.translation import gettext as _\nfrom rest_framework.exceptions import PermissionDenied\nfrom rest_framework.exceptions import ValidationError\n\nfrom bothub.common.models import RepositoryTranslatedExample\n\n\nclass CanContributeInRepositoryValidator(object):\n    def __call__(self, value):\n        user_authorization = value.get_user_authorization(\n            self.request.user)\n        if not user_authorization.can_contribute:\n            raise PermissionDenied(\n                _('You can\\'t contribute in this repository'))\n\n    def set_context(self, serializer):\n        self.request = serializer.context.get('request')\n\n\nclass CanContributeInRepositoryExampleValidator(object):\n    def __call__(self, value):\n        repository = value.repository_update.repository\n        user_authorization = repository.get_user_authorization(\n            self.request.user)\n        if not user_authorization.can_contribute:\n            raise PermissionDenied(\n                _('You can\\'t contribute in this repository'))\n\n    def set_context(self, serializer):\n        self.request = serializer.context.get('request')\n\n\nclass CanContributeInRepositoryTranslatedExampleValidator(object):\n    def __call__(self, value):\n        repository = value.original_example.repository_update.repository\n        user_authorization = repository.get_user_authorization(\n            self.request.user)\n        if not user_authorization.can_contribute:\n            raise PermissionDenied(\n                _('You can\\'t contribute in this repository'))\n\n    def set_context(self, serializer):\n        self.request = serializer.context.get('request')\n\n\nclass TranslatedExampleEntitiesValidator(object):\n    def __call__(self, attrs):\n        original_example = attrs.get('original_example')\n        entities_valid = RepositoryTranslatedExample.same_entities_validator(\n            list(map(lambda x: dict(x), attrs.get('entities'))),\n            list(map(lambda x: x.to_dict, original_example.entities.all())))\n        if not entities_valid:\n            raise ValidationError({'entities': _('Invalid entities')})\n\n\nclass TranslatedExampleLanguageValidator(object):\n    def __call__(self, attrs):\n        original_example = attrs.get('original_example')\n        language = attrs.get('language')\n        if original_example.repository_update.language == language:\n            raise ValidationError({'language': _(\n                'Can\\'t translate to the same language')})\n\n\nclass ExampleWithIntentOrEntityValidator(object):\n    def __call__(self, attrs):\n        intent = attrs.get('intent')\n        entities = attrs.get('entities')\n\n        if not intent and not entities:\n            raise ValidationError(_('Define a intent or one entity'))\n", "path": "bothub/api/validators.py"}, {"content": "from rest_framework import serializers\n\nfrom django.utils.translation import gettext as _\n\nfrom bothub.common.models import Repository\nfrom bothub.common.models import RepositoryExample\nfrom bothub.common.models import RepositoryExampleEntity\n\nfrom ..fields import EntityText\nfrom ..validators import CanContributeInRepositoryExampleValidator\nfrom ..validators import CanContributeInRepositoryValidator\nfrom ..validators import ExampleWithIntentOrEntityValidator\nfrom .translate import RepositoryTranslatedExampleSerializer\n\n\nclass RepositoryExampleEntitySerializer(serializers.ModelSerializer):\n    class Meta:\n        model = RepositoryExampleEntity\n        fields = [\n            'id',\n            'repository_example',\n            'start',\n            'end',\n            'entity',\n            'created_at',\n            'value',\n        ]\n\n    repository_example = serializers.PrimaryKeyRelatedField(\n        queryset=RepositoryExample.objects,\n        validators=[\n            CanContributeInRepositoryExampleValidator(),\n        ],\n        help_text=_('Example\\'s ID'))\n    value = serializers.SerializerMethodField()\n\n    def get_value(self, obj):\n        return obj.value\n\n\nclass NewRepositoryExampleEntitySerializer(serializers.ModelSerializer):\n    class Meta:\n        model = RepositoryExampleEntity\n        fields = [\n            'repository_example',\n            'start',\n            'end',\n            'entity',\n        ]\n\n\nclass RepositoryExampleSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = RepositoryExample\n        fields = [\n            'id',\n            'repository_update',\n            'deleted_in',\n            'text',\n            'intent',\n            'language',\n            'created_at',\n            'entities',\n            'translations',\n        ]\n        read_only_fields = [\n            'repository_update',\n            'deleted_in',\n        ]\n\n    entities = RepositoryExampleEntitySerializer(\n        many=True,\n        read_only=True)\n    translations = RepositoryTranslatedExampleSerializer(\n        many=True,\n        read_only=True)\n    language = serializers.SerializerMethodField()\n\n    def get_language(self, obj):\n        return obj.language\n\n\nclass NewRepositoryExampleSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = RepositoryExample\n        fields = [\n            'id',\n            'repository',\n            'repository_update',\n            'text',\n            'entities',\n            'intent',\n        ]\n\n    id = serializers.PrimaryKeyRelatedField(\n        read_only=True,\n        style={'show': False})\n    text = EntityText(style={'entities_field': 'entities'})\n    repository = serializers.PrimaryKeyRelatedField(\n        queryset=Repository.objects,\n        validators=[\n            CanContributeInRepositoryValidator(),\n        ],\n        source='repository_update',\n        style={'show': False})\n    repository_update = serializers.PrimaryKeyRelatedField(\n        read_only=True,\n        style={'show': False})\n    entities = NewRepositoryExampleEntitySerializer(\n        many=True,\n        style={'text_field': 'text'})\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.validators.append(ExampleWithIntentOrEntityValidator())\n\n    def validate_repository(self, repository):\n        return repository.current_update()\n\n    def create(self, validated_data):\n        entities_data = validated_data.pop('entities')\n        example = self.Meta.model.objects.create(**validated_data)\n        for entity_data in entities_data:\n            RepositoryExampleEntity.objects.create(\n                repository_example=example,\n                **entity_data)\n        return example\n", "path": "bothub/api/serializers/example.py"}]}