more improvements on tool calling

This commit is contained in:
2026-03-06 09:08:16 -07:00
parent b89d4e5a28
commit 7c7e763809
7 changed files with 275 additions and 142 deletions

View File

@@ -19,6 +19,7 @@ defmodule ElixirAi.ChatUtils do
headers = [{"authorization", "Bearer #{api_key}"}]
Logger.info("sending AI request with body: #{inspect(body)}")
case Req.post(api_url,
json: body,
headers: headers,
@@ -39,6 +40,28 @@ defmodule ElixirAi.ChatUtils do
end)
end
def api_message(%{role: :assistant, tool_calls: [_ | _] = tool_calls} = msg) do
%{
role: "assistant",
content: Map.get(msg, :content, ""),
tool_calls:
Enum.map(tool_calls, fn call ->
%{
id: call.id,
type: "function",
function: %{
name: call.name,
arguments: call.arguments
}
}
end)
}
end
def api_message(%{role: :tool, tool_call_id: tool_call_id, content: content}) do
%{role: "tool", tool_call_id: tool_call_id, content: content}
end
def api_message(%{role: role, content: content}) do
%{role: Atom.to_string(role), content: content}
end