runner code refactor, frontend papercuts
Some checks failed
CI/CD Pipeline / build (push) Failing after 4s

This commit is contained in:
2026-03-23 13:13:55 -06:00
parent 6ecd7d9d31
commit d5cd472bf5
15 changed files with 616 additions and 519 deletions

View File

@@ -30,12 +30,16 @@ defmodule ElixirAi.ChatUtils do
Task.start_link(fn ->
try do
result = function.(args)
send(server, {:tool_response, current_message_id, tool_call_id, result})
send(server, {:stream, {:tool_response, current_message_id, tool_call_id, result}})
rescue
e ->
reason = Exception.format(:error, e, __STACKTRACE__)
Logger.error("Tool task crashed: #{reason}")
send(server, {:tool_response, current_message_id, tool_call_id, {:error, reason}})
send(
server,
{:stream, {:tool_response, current_message_id, tool_call_id, {:error, reason}}}
)
end
end)
end
@@ -91,7 +95,7 @@ defmodule ElixirAi.ChatUtils do
{:error, reason} ->
Logger.warning("AI request failed: #{inspect(reason)} for #{api_url}")
send(server, {:ai_request_error, reason})
send(server, {:stream, {:ai_request_error, reason}})
end
end)
end

View File

@@ -29,7 +29,7 @@ defmodule ElixirAi.AiUtils.StreamLineUtils do
}) do
send(
server,
{:start_new_ai_response, id}
{:stream, {:start_new_ai_response, id}}
)
end
@@ -45,7 +45,7 @@ defmodule ElixirAi.AiUtils.StreamLineUtils do
send(
server,
{:ai_text_stream_finish, id}
{:stream, {:ai_text_stream_finish, id}}
)
end
@@ -61,7 +61,7 @@ defmodule ElixirAi.AiUtils.StreamLineUtils do
}) do
send(
server,
{:ai_reasoning_chunk, id, reasoning_content}
{:stream, {:ai_reasoning_chunk, id, reasoning_content}}
)
end
@@ -77,7 +77,7 @@ defmodule ElixirAi.AiUtils.StreamLineUtils do
}) do
send(
server,
{:ai_text_chunk, id, reasoning_content}
{:stream, {:ai_text_chunk, id, reasoning_content}}
)
end
@@ -105,12 +105,13 @@ defmodule ElixirAi.AiUtils.StreamLineUtils do
send(
server,
{:ai_tool_call_start, id, {tool_name, tool_args_start, tool_index, tool_call_id}}
{:stream,
{:ai_tool_call_start, id, {tool_name, tool_args_start, tool_index, tool_call_id}}}
)
%{"index" => tool_index, "function" => %{"arguments" => tool_args_diff}} ->
# Logger.info("Received tool call middle for index #{tool_index}")
send(server, {:ai_tool_call_middle, id, {tool_args_diff, tool_index}})
send(server, {:stream, {:ai_tool_call_middle, id, {tool_args_diff, tool_index}}})
other ->
Logger.warning("Unmatched tool call item: #{inspect(other)}")
@@ -126,7 +127,7 @@ defmodule ElixirAi.AiUtils.StreamLineUtils do
}
) do
# Logger.info("Received tool_calls_finished with message: #{inspect(message)}")
send(server, {:ai_tool_call_end, id})
send(server, {:stream, {:ai_tool_call_end, id}})
end
def handle_stream_line(_server, %{"error" => error_info}) do