Fix review blockers in record chat

- Add Task.Supervisor to app supervision tree
- Use tagged tuples instead of rescue for error handling
- Pass embedding_text from parent LiveView as prop
- Remove dead Completion struct fields
- Extract socket assigns before Task closure
- Log errors server-side, show generic user message
- Make build_system_prompt private, remove thin wrapper
- Extract do_send_message for retry reuse

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Claudio Ortolina
2026-02-22 10:20:58 +00:00
parent 6e6e419801
commit 8d38512712
10 changed files with 99 additions and 91 deletions
+1
View File
@@ -23,6 +23,7 @@ defmodule MusicLibrary.Application do
{Oban, Application.fetch_env!(:music_library, Oban)},
{Ecto.Migrator,
repos: Application.fetch_env!(:music_library, :ecto_repos), skip: skip_migrations?()},
{Task.Supervisor, name: MusicLibrary.TaskSupervisor},
{Phoenix.PubSub, name: MusicLibrary.PubSub},
{LastFm.Supervisor, LastFm.Config.resolve(:music_library)},
# Start a worker by calling: MusicLibrary.Worker.start_link(arg)
+2 -6
View File
@@ -1,5 +1,5 @@
defmodule MusicLibrary.RecordChat do
alias MusicLibrary.Records.{Record, Similarity}
alias MusicLibrary.Records.Record
def stream_response(messages, record, embedding_text, callback) do
system_prompt = build_system_prompt(record, embedding_text)
@@ -11,11 +11,7 @@ defmodule MusicLibrary.RecordChat do
OpenAI.chat_stream(full_messages, on_chunk: callback)
end
def get_embedding_text(record_id) do
Similarity.get_embedding_text(record_id)
end
def build_system_prompt(%Record{} = record, embedding_text) do
defp build_system_prompt(%Record{} = record, embedding_text) do
context =
case embedding_text do
nil -> basic_context(record)