From ec12be613be1e5e10f561216f7527ff722d71bd3 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sat, 4 Apr 2026 23:31:20 +0100 Subject: [PATCH] Extract a default prompt --- docs/architecture.md | 1 + lib/music_library/chats/artist_chat.ex | 15 ++++++--------- lib/music_library/chats/default_prompt.ex | 21 +++++++++++++++++++++ lib/music_library/chats/record_chat.ex | 13 +++++-------- 4 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 lib/music_library/chats/default_prompt.ex diff --git a/docs/architecture.md b/docs/architecture.md index b0f96c9b..d10e1df6 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -129,6 +129,7 @@ Last.fm schemas (separate, not Ecto-persisted to main DB): | `Chats.StreamProvider` | Behaviour for streaming AI chat (`stream_response/3` callback) | | `Chats.RecordChat` | Chat implementation for records (OpenAI streaming, web search enabled) | | `Chats.ArtistChat` | Chat implementation for artists (OpenAI streaming, uses Wikipedia/artist context) | +| `Chats.DefaultPrompt` | Shared default prompt fragments (identity, approach) for chat implementations | | `Country` | Country code (alpha-2, alpha-3, subdivision, IETF) to flag emoji conversion | | `ErrorTracker.ErrorNotifier` | GenServer: attaches to ErrorTracker telemetry, skips muted errors, throttles repeated errors, dispatches email notifications | | `ErrorTracker.ErrorNotifier.Email` | Builds and sends Swoosh error notification emails with stack trace formatting | diff --git a/lib/music_library/chats/artist_chat.ex b/lib/music_library/chats/artist_chat.ex index 95ea3e89..4fea1f76 100644 --- a/lib/music_library/chats/artist_chat.ex +++ b/lib/music_library/chats/artist_chat.ex @@ -6,6 +6,7 @@ defmodule MusicLibrary.Chats.ArtistChat do @behaviour MusicLibrary.Chats.StreamProvider alias MusicLibrary.Artists.ArtistInfo + alias MusicLibrary.Chats.DefaultPrompt @impl true @spec stream_response([map()], {map(), ArtistInfo.t()}, (String.t() -> any())) :: @@ -20,17 +21,13 @@ defmodule MusicLibrary.Chats.ArtistChat do context = build_context(artist, artist_info) """ - You are a knowledgeable music assistant. Answer questions about the artist \ - the user is currently viewing. Use the provided artist information as your \ - primary reference, and use web search to find additional up-to-date \ - information when helpful. Be concise and accurate. When unsure, say so. \ - Include links when they add genuine value, but not on every response. + #{DefaultPrompt.identity()} + Answer questions about the artist the user is currently viewing. \ + Use the provided artist information as your primary reference, \ - Vary your response style and structure. Don't repeat information already \ - discussed in the conversation. Refer back to earlier points naturally \ - instead of restating them. + #{DefaultPrompt.approach()} - Artist information: + Album information: #{context} """ end diff --git a/lib/music_library/chats/default_prompt.ex b/lib/music_library/chats/default_prompt.ex new file mode 100644 index 00000000..0462aae5 --- /dev/null +++ b/lib/music_library/chats/default_prompt.ex @@ -0,0 +1,21 @@ +defmodule MusicLibrary.Chats.DefaultPrompt do + @moduledoc false + + def identity do + """ + You are a knowledgeable music assistant. + """ + end + + def approach do + """ + Use web search to find additional up-to-date \ + information when helpful. Be concise and accurate. When unsure, say so. \ + Include links when they add genuine value, but not on every response. + + Vary your response style and structure. Don't repeat information already \ + discussed in the conversation. Refer back to earlier points naturally \ + instead of restating them. + """ + end +end diff --git a/lib/music_library/chats/record_chat.ex b/lib/music_library/chats/record_chat.ex index 7f562d86..bcd70e4e 100644 --- a/lib/music_library/chats/record_chat.ex +++ b/lib/music_library/chats/record_chat.ex @@ -5,6 +5,7 @@ defmodule MusicLibrary.Chats.RecordChat do @behaviour MusicLibrary.Chats.StreamProvider + alias MusicLibrary.Chats.DefaultPrompt alias MusicLibrary.Records.Record @impl true @@ -25,15 +26,11 @@ defmodule MusicLibrary.Chats.RecordChat do end """ - You are a knowledgeable music assistant. Answer questions about the album \ - the user is currently viewing. Use the provided album information as your \ - primary reference, and use web search to find additional up-to-date \ - information when helpful. Be concise and accurate. When unsure, say so. \ - Include links when they add genuine value, but not on every response. + #{DefaultPrompt.identity()} + Answer questions about the album the user is currently viewing. \ + Use the provided album information as your primary reference, \ - Vary your response style and structure. Don't repeat information already \ - discussed in the conversation. Refer back to earlier points naturally \ - instead of restating them. + #{DefaultPrompt.approach()} Album information: #{context}