better process tracking for admin dashboard
Some checks failed
CI/CD Pipeline / build (push) Failing after 5s
Some checks failed
CI/CD Pipeline / build (push) Failing after 5s
This commit is contained in:
@@ -10,13 +10,12 @@ defmodule ElixirAiWeb.ChatLive do
|
||||
|
||||
def mount(%{"name" => name}, _session, socket) do
|
||||
case ConversationManager.open_conversation(name) do
|
||||
{:ok, _pid} ->
|
||||
{:ok, conversation} ->
|
||||
if connected?(socket) do
|
||||
Phoenix.PubSub.subscribe(ElixirAi.PubSub, chat_topic(name))
|
||||
:pg.join(ElixirAi.LiveViewPG, {:liveview, __MODULE__}, self())
|
||||
end
|
||||
|
||||
conversation = ChatRunner.get_conversation(name)
|
||||
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(conversation_name: name)
|
||||
@@ -25,7 +24,8 @@ defmodule ElixirAiWeb.ChatLive do
|
||||
|> assign(streaming_response: conversation.streaming_response)
|
||||
|> assign(background_color: "bg-cyan-950/30")
|
||||
|> assign(provider: conversation.provider)
|
||||
|> assign(db_error: nil)}
|
||||
|> assign(db_error: nil)
|
||||
|> assign(ai_error: nil)}
|
||||
|
||||
{:error, :not_found} ->
|
||||
{:ok, push_navigate(socket, to: "/")}
|
||||
@@ -41,7 +41,8 @@ defmodule ElixirAiWeb.ChatLive do
|
||||
|> assign(streaming_response: nil)
|
||||
|> assign(background_color: "bg-cyan-950/30")
|
||||
|> assign(provider: nil)
|
||||
|> assign(db_error: Exception.format(:error, reason))}
|
||||
|> assign(db_error: Exception.format(:error, reason))
|
||||
|> assign(ai_error: nil)}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,6 +61,11 @@ defmodule ElixirAiWeb.ChatLive do
|
||||
Database error: {@db_error}
|
||||
</div>
|
||||
<% end %>
|
||||
<%= if @ai_error do %>
|
||||
<div class="mx-4 mt-2 px-3 py-2 rounded text-sm text-red-400 bg-red-950/40" role="alert">
|
||||
AI error: {@ai_error}
|
||||
</div>
|
||||
<% end %>
|
||||
<div
|
||||
id="chat-messages"
|
||||
phx-hook="ScrollBottom"
|
||||
@@ -118,6 +124,10 @@ defmodule ElixirAiWeb.ChatLive do
|
||||
{:noreply, assign(socket, user_input: "")}
|
||||
end
|
||||
|
||||
def handle_info(:recovery_restart, socket) do
|
||||
{:noreply, assign(socket, streaming_response: nil, ai_error: nil)}
|
||||
end
|
||||
|
||||
def handle_info({:user_chat_message, message}, socket) do
|
||||
{:noreply,
|
||||
socket
|
||||
@@ -210,6 +220,16 @@ defmodule ElixirAiWeb.ChatLive do
|
||||
{:noreply, assign(socket, db_error: reason)}
|
||||
end
|
||||
|
||||
def handle_info({:ai_request_error, reason}, socket) do
|
||||
error_message =
|
||||
case reason do
|
||||
%{__struct__: mod, reason: r} -> "#{inspect(mod)}: #{inspect(r)}"
|
||||
_ -> inspect(reason)
|
||||
end
|
||||
|
||||
{:noreply, assign(socket, ai_error: error_message, streaming_response: nil)}
|
||||
end
|
||||
|
||||
def handle_info({:set_background_color, color}, socket) do
|
||||
Logger.info("setting background color to #{color}")
|
||||
{:noreply, assign(socket, background_color: color)}
|
||||
|
||||
Reference in New Issue
Block a user