Add collection sentinel UUID to Chats context
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
defmodule MusicLibrary.Chats do
|
||||
@moduledoc """
|
||||
Persistent storage for AI chat conversations about records and artists.
|
||||
Persistent storage for AI chat conversations about records, artists, and the collection.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
@@ -8,6 +8,11 @@ defmodule MusicLibrary.Chats do
|
||||
alias MusicLibrary.Chats.{Chat, Message}
|
||||
alias MusicLibrary.Repo
|
||||
|
||||
@collection_musicbrainz_id "00000000-0000-0000-0000-000000000000"
|
||||
|
||||
@spec collection_musicbrainz_id() :: String.t()
|
||||
def collection_musicbrainz_id, do: @collection_musicbrainz_id
|
||||
|
||||
@spec list_chats(atom(), String.t()) :: [Chat.t()]
|
||||
def list_chats(entity, musicbrainz_id) do
|
||||
message_count_query =
|
||||
|
||||
@@ -43,6 +43,15 @@ defmodule MusicLibrary.ChatsTest do
|
||||
|
||||
assert Chats.count_chats(:artist, @musicbrainz_id) == 0
|
||||
end
|
||||
|
||||
test "counts collection chats" do
|
||||
Chats.create_chat_with_message(
|
||||
%{entity: :collection, musicbrainz_id: Chats.collection_musicbrainz_id()},
|
||||
%{role: "user", content: "Tell me about my collection"}
|
||||
)
|
||||
|
||||
assert Chats.count_chats(:collection, Chats.collection_musicbrainz_id()) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "list_chats/2" do
|
||||
@@ -133,6 +142,25 @@ defmodule MusicLibrary.ChatsTest do
|
||||
%{role: "user", content: "Hello"}
|
||||
)
|
||||
end
|
||||
|
||||
test "creates chat with collection entity" do
|
||||
assert {:ok, chat} =
|
||||
Chats.create_chat_with_message(
|
||||
%{entity: :collection, musicbrainz_id: Chats.collection_musicbrainz_id()},
|
||||
%{role: "user", content: "What prog rock do I have?"}
|
||||
)
|
||||
|
||||
assert chat.entity == :collection
|
||||
assert chat.musicbrainz_id == Chats.collection_musicbrainz_id()
|
||||
assert chat.topic == "What prog rock do I have?"
|
||||
end
|
||||
end
|
||||
|
||||
describe "collection_musicbrainz_id/0" do
|
||||
test "returns a valid UUID" do
|
||||
id = Chats.collection_musicbrainz_id()
|
||||
assert {:ok, _} = Ecto.UUID.cast(id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "add_message/2" do
|
||||
|
||||
Reference in New Issue
Block a user