Enable chat for artists

This commit is contained in:
Claudio Ortolina
2026-02-22 15:31:09 +00:00
parent b9ee7a6ce9
commit 60d81e14de
10 changed files with 156 additions and 51 deletions
@@ -1,9 +1,8 @@
defmodule MusicLibraryWeb.Components.RecordChat do
defmodule MusicLibraryWeb.Components.Chat do
use MusicLibraryWeb, :live_component
require Logger
alias MusicLibrary.RecordChat
alias MusicLibraryWeb.Markdown
def open(id), do: Fluxon.open_dialog(id)
@@ -55,7 +54,7 @@ defmodule MusicLibraryWeb.Components.RecordChat do
>
<div class="flex items-center gap-2 pb-4 border-b border-zinc-200 dark:border-zinc-700">
<h2 class="text-lg font-semibold text-zinc-900 dark:text-zinc-100">
{gettext("Chat about %{title}", title: @record.title)}
{gettext("Chat about %{title}", title: @title)}
</h2>
<.button
:if={@messages != []}
@@ -82,10 +81,7 @@ defmodule MusicLibraryWeb.Components.RecordChat do
name="hero-chat-bubble-left-right"
class="size-12 mb-4 text-zinc-300 dark:text-zinc-600"
/>
<p class="text-sm font-medium">{gettext("Ask anything about this album")}</p>
<p class="text-xs mt-1">
{gettext("e.g. \"What genre is this?\", \"Tell me about the artists\"")}
</p>
<p class="text-sm font-medium">{@empty_prompt}</p>
</div>
<div
@@ -144,7 +140,7 @@ defmodule MusicLibraryWeb.Components.RecordChat do
<.input
name="message"
value=""
placeholder={gettext("Ask about this album...")}
placeholder={@placeholder}
class="flex-1"
disabled={@loading}
autocomplete="off"
@@ -215,11 +211,11 @@ defmodule MusicLibraryWeb.Components.RecordChat do
user_message = %{role: "user", content: String.trim(text)}
messages = socket.assigns.messages ++ [user_message]
record = socket.assigns.record
embedding_text = socket.assigns.embedding_text
chat_module = socket.assigns.chat_module
chat_context = socket.assigns.chat_context
Task.Supervisor.start_child(MusicLibrary.TaskSupervisor, fn ->
case RecordChat.stream_response(messages, record, embedding_text, fn chunk ->
case chat_module.stream_response(messages, chat_context, fn chunk ->
Phoenix.LiveView.send_update(parent_pid, __MODULE__,
id: component_id,
chunk: chunk
@@ -232,7 +228,7 @@ defmodule MusicLibraryWeb.Components.RecordChat do
)
{:error, reason} ->
Logger.error("RecordChat streaming error: #{reason}")
Logger.error("Chat streaming error: #{reason}")
Phoenix.LiveView.send_update(parent_pid, __MODULE__,
id: component_id,
@@ -21,6 +21,18 @@
data-slot="icon"
/>
</.button>
<.button
variant="soft"
phx-click={MusicLibraryWeb.Components.Chat.open("artist-chat-sheet")}
>
<span class="sr-only">{gettext("Chat about artist")}</span>
<.icon
name="hero-chat-bubble-left-right"
class="h-5 w-5"
aria-hidden="true"
data-slot="icon"
/>
</.button>
<.dropdown id={"actions-#{@artist.musicbrainz_id}"} placement="bottom-end">
<:toggle>
<.button variant="soft">
@@ -332,6 +344,17 @@
musicbrainz_id={@artist.musicbrainz_id}
/>
<.live_component
id="artist-chat"
sheet_id="artist-chat-sheet"
module={MusicLibraryWeb.Components.Chat}
title={@artist.name}
chat_module={MusicLibrary.ArtistChat}
chat_context={{@artist, @artist_info}}
placeholder={gettext("Ask about this artist...")}
empty_prompt={gettext("Ask anything about this artist")}
/>
<.structured_modal
:if={@live_action == :edit}
id="artist-info-modal"
@@ -28,7 +28,7 @@
</.button>
<.button
variant="soft"
phx-click={MusicLibraryWeb.Components.RecordChat.open("record-chat-sheet")}
phx-click={MusicLibraryWeb.Components.Chat.open("record-chat-sheet")}
>
<span class="sr-only">{gettext("Chat about album")}</span>
<.icon
@@ -342,9 +342,12 @@
<.live_component
id="record-chat"
sheet_id="record-chat-sheet"
module={MusicLibraryWeb.Components.RecordChat}
record={@record}
embedding_text={@embedding_text}
module={MusicLibraryWeb.Components.Chat}
title={@record.title}
chat_module={MusicLibrary.RecordChat}
chat_context={{@record, @embedding_text}}
placeholder={gettext("Ask about this album...")}
empty_prompt={gettext("Ask anything about this album")}
/>
<.structured_modal
@@ -16,7 +16,7 @@
<.button_group>
<.button
variant="soft"
phx-click={MusicLibraryWeb.Components.RecordChat.open("record-chat-sheet")}
phx-click={MusicLibraryWeb.Components.Chat.open("record-chat-sheet")}
>
<span class="sr-only">{gettext("Chat about album")}</span>
<.icon
@@ -307,9 +307,12 @@
<.live_component
id="record-chat"
sheet_id="record-chat-sheet"
module={MusicLibraryWeb.Components.RecordChat}
record={@record}
embedding_text={@embedding_text}
module={MusicLibraryWeb.Components.Chat}
title={@record.title}
chat_module={MusicLibrary.RecordChat}
chat_context={{@record, @embedding_text}}
placeholder={gettext("Ask about this album...")}
empty_prompt={gettext("Ask anything about this album")}
/>
<.structured_modal