Can fetch genres from OpenAI

This commit is contained in:
Claudio Ortolina
2024-12-10 16:45:29 +03:00
parent 1cd38e5358
commit b68a7ac734
8 changed files with 156 additions and 51 deletions
+21
View File
@@ -185,6 +185,27 @@ defmodule MusicLibrary.Records do
end
end
def populate_genres(record) do
artists =
record.artists
|> Enum.map(fn a -> a.name end)
|> Enum.join(",")
prompt = """
Provide a list of music genres applicable to the album "#{record.title}" by #{artists}.
Limit the list to 5 genres, ordered by decreasing specificity, all lowercase.
Return a valid JSON list.
"""
{:ok, response} = OpenAI.gpt(prompt)
record
|> Record.add_genres(response["genres"])
|> Repo.update()
end
defp get_cover_art_or_default(musicbrainz_id) do
case music_brainz_config().api.get_cover_art(
{:musicbrainz_id, musicbrainz_id},
+4
View File
@@ -84,6 +84,10 @@ defmodule MusicLibrary.Records.Record do
|> put_embed(:artists, artists_attrs)
end
def add_genres(record, genres) do
change(record, genres: genres)
end
def add_cover_data(record, cover_data) do
record
|> change(cover_data: cover_data)