Close TD-22 chat delete transaction
This commit is contained in:
@@ -106,12 +106,24 @@ defmodule BDS.AI.Chat do
|
||||
{:error, :not_found}
|
||||
|
||||
%ChatConversation{} = conversation ->
|
||||
Repo.delete_all(
|
||||
from message in ChatMessage, where: message.conversation_id == ^conversation_id
|
||||
)
|
||||
Repo.transaction(fn ->
|
||||
Repo.delete_all(
|
||||
from message in ChatMessage, where: message.conversation_id == ^conversation_id
|
||||
)
|
||||
|
||||
case Repo.delete(conversation) do
|
||||
{:ok, _conversation} -> {:ok, :deleted}
|
||||
case delete_chat_conversation_test_hook(conversation_id) do
|
||||
:ok ->
|
||||
case Repo.delete(conversation) do
|
||||
{:ok, _conversation} -> :ok
|
||||
{:error, reason} -> Repo.rollback(reason)
|
||||
end
|
||||
|
||||
{:error, reason} ->
|
||||
Repo.rollback(reason)
|
||||
end
|
||||
end)
|
||||
|> case do
|
||||
{:ok, :ok} -> {:ok, :deleted}
|
||||
{:error, reason} -> {:error, reason}
|
||||
end
|
||||
end
|
||||
@@ -610,6 +622,13 @@ defmodule BDS.AI.Chat do
|
||||
end
|
||||
end
|
||||
|
||||
defp delete_chat_conversation_test_hook(conversation_id) do
|
||||
case Application.get_env(:bds, :chat_delete_conversation_test_hook) do
|
||||
hook when is_function(hook, 1) -> hook.(conversation_id)
|
||||
_other -> :ok
|
||||
end
|
||||
end
|
||||
|
||||
defp persist_assistant_response(conversation_id, response) do
|
||||
usage = normalize_usage(response.usage)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user