This commit is contained in:
@@ -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: %{}
|
||||
}}
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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, _} ->
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user