Skip to content

Commit

Permalink
Expose provider in the API tags response (#4280)
Browse files Browse the repository at this point in the history
* Expose provider in TagsSerializer

* Add some machine-generated labels to sample data

* Update documentation examples

* Fix some tests

* Allow the provider field to be nullable for ES compatibility

* Update phrasing

Co-authored-by: zack <6351754+zackkrida@users.noreply.github.com>

---------

Co-authored-by: zack <6351754+zackkrida@users.noreply.github.com>
  • Loading branch information
AetherUnbound and zackkrida authored May 7, 2024
1 parent c805d4f commit 8e6b884
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 36 deletions.
20 changes: 10 additions & 10 deletions api/api/examples/audio_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
"filesize": 7139840,
"filetype": "mp3",
"tags": [
{"accuracy": None, "name": "vocal"},
{"accuracy": None, "name": "female"},
{"accuracy": None, "name": "speed_medium"},
{"accuracy": None, "name": "guitar"},
{"accuracy": None, "name": "strings"},
{"accuracy": None, "name": "energetic"},
{"accuracy": None, "name": "acoustic"},
{"accuracy": None, "name": "vocal"},
{"accuracy": None, "name": "voice"},
{"accuracy": None, "name": "funkyhouse"},
{"accuracy": None, "name": "vocal", "unstable__provider": "jamendo"},
{"accuracy": None, "name": "female", "unstable__provider": "jamendo"},
{"accuracy": None, "name": "speed_medium", "unstable__provider": "jamendo"},
{"accuracy": None, "name": "guitar", "unstable__provider": "jamendo"},
{"accuracy": None, "name": "strings", "unstable__provider": "jamendo"},
{"accuracy": None, "name": "energetic", "unstable__provider": "jamendo"},
{"accuracy": None, "name": "acoustic", "unstable__provider": "jamendo"},
{"accuracy": None, "name": "vocal", "unstable__provider": "jamendo"},
{"accuracy": None, "name": "voice", "unstable__provider": "jamendo"},
{"accuracy": None, "name": "funkyhouse", "unstable__provider": "jamendo"},
],
"alt_files": None,
"attribution": '"Wish You Were Here" by The.madpix.project is licensed under CC BY-NC-SA 3.0. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/.', # noqa: E501,
Expand Down
45 changes: 24 additions & 21 deletions api/api/examples/image_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,30 @@
"filesize": 896128,
"filetype": "jpg",
"tags": [
{"accuracy": None, "name": "tree"},
{"accuracy": None, "name": "bark"},
{"accuracy": None, "name": "texture"},
{"accuracy": None, "name": "wood"},
{"accuracy": None, "name": "nature"},
{"accuracy": None, "name": "pattern"},
{"accuracy": None, "name": "rough"},
{"accuracy": None, "name": "surface"},
{"accuracy": None, "name": "brown"},
{"accuracy": None, "name": "old"},
{"accuracy": None, "name": "background"},
{"accuracy": None, "name": "trunk"},
{"accuracy": None, "name": "natural"},
{"accuracy": None, "name": "forest"},
{"accuracy": None, "name": "detail"},
{"accuracy": None, "name": "lumber"},
{"accuracy": None, "name": "weathered"},
{"accuracy": None, "name": "timber"},
{"accuracy": None, "name": "stump"},
{"accuracy": None, "name": "closeup"},
{"accuracy": None, "name": "root"},
{"accuracy": None, "name": "tree", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "bark", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "texture", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "wood", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "nature", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "pattern", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "rough", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "surface", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "brown", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "old", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "background", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "trunk", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "natural", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "forest", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "detail", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "lumber", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "weathered", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "timber", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "stump", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "closeup", "unstable__provider": "stocksnap"},
{"accuracy": None, "name": "root", "unstable__provider": "stocksnap"},
{"accuracy": 0.95, "name": "tree", "unstable__provider": "machine_example"},
{"accuracy": 0.9, "name": "bark", "unstable__provider": "machine_example"},
{"accuracy": 0.98, "name": "plant", "unstable__provider": "machine_example"},
],
"attribution": (
'"Tree Bark Photo" by Tim Sullivan is marked with '
Expand Down
10 changes: 10 additions & 0 deletions api/api/serializers/media_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,16 @@ class TagSerializer(serializers.Serializer):
help_text="The accuracy of a machine-generated tag. Human-generated "
"tags have a null accuracy field.",
)
unstable__provider = serializers.CharField(
label="provider",
source="provider",
# Provider is present in the database but not in Elasticsearch, so it may
# not always be present during serialization
allow_null=True,
help_text="The source of the tag. When this field matches the provider for the "
"record, the tag originated from the upstream provider. Otherwise, the tag "
"was added with an external machine-generated labeling processes.",
)


@extend_schema_serializer(
Expand Down
5 changes: 3 additions & 2 deletions api/test/factory/models/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ class Meta:
url = Faker("globally_unique_url")
thumbnail = Faker("image_url")
title = Faker("sentence", nb_words=4)
tags = factory.List(
[
tags = factory.LazyAttribute(
lambda o: [
{
"name": CREATED_BY_FIXTURE_MARKER,
"provider": o.provider,
}
]
)
Expand Down
Loading

0 comments on commit 8e6b884

Please sign in to comment.