general solution to voice control
Some checks failed
CI/CD Pipeline / build (push) Failing after 4s

This commit is contained in:
2026-03-25 09:22:48 -06:00
parent 86ff82a015
commit d857e91241
14 changed files with 309 additions and 31 deletions

View File

@@ -50,6 +50,10 @@ defmodule ElixirAi.ChatRunner do
GenServer.call(via(name), {:session, {:deregister_liveview_pid, liveview_pid}})
end
def register_page_tools(name, page_tools) when is_list(page_tools) do
GenServer.call(via(name), {:session, {:register_page_tools, page_tools}})
end
def get_conversation(name) do
GenServer.call(via(name), {:conversation, :get_conversation})
end
@@ -130,6 +134,7 @@ defmodule ElixirAi.ChatRunner do
tool_choice: tool_choice,
server_tools: server_tools,
liveview_tools: liveview_tools,
page_tools: [],
provider: provider,
liveview_pids: %{}
}}

View File

@@ -11,7 +11,7 @@ defmodule ElixirAi.ChatRunner.ConversationCalls do
ElixirAi.ChatUtils.request_ai_response(
self(),
messages_with_system_prompt(new_state.messages, state.system_prompt),
state.server_tools ++ state.liveview_tools,
state.server_tools ++ state.liveview_tools ++ state.page_tools,
state.provider,
effective_tool_choice
)

View File

@@ -10,6 +10,10 @@ defmodule ElixirAi.ChatRunner.LiveviewSession do
{:reply, :ok, %{state | liveview_pids: Map.put(state.liveview_pids, liveview_pid, ref)}}
end
def handle_call({:register_page_tools, page_tools}, _from, state) do
{:reply, :ok, %{state | page_tools: page_tools}}
end
def handle_call({:deregister_liveview_pid, liveview_pid}, _from, state) do
case Map.pop(state.liveview_pids, liveview_pid) do
{nil, _} ->

View File

@@ -111,7 +111,7 @@ defmodule ElixirAi.ChatRunner.StreamHandler do
{failed, pending} ->
with {:ok, decoded_args} <- Jason.decode(tool_call.arguments),
tool when not is_nil(tool) <-
Enum.find(state.server_tools ++ state.liveview_tools, fn t ->
Enum.find(state.server_tools ++ state.liveview_tools ++ state.page_tools, fn t ->
t.name == tool_call.name
end) do
tool.run_function.(id, tool_call.id, decoded_args)
@@ -160,7 +160,7 @@ defmodule ElixirAi.ChatRunner.StreamHandler do
ElixirAi.ChatUtils.request_ai_response(
self(),
messages_with_system_prompt(state.messages ++ [new_message], state.system_prompt),
state.server_tools ++ state.liveview_tools,
state.server_tools ++ state.liveview_tools ++ state.page_tools,
state.provider,
state.tool_choice
)