Skip to content

Commit e1069ff

Browse files
authored
Added support for native tool calls to vertex ai. (brainlid#359)
1 parent 4b1422e commit e1069ff

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/chat_models/chat_vertex_ai.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ defmodule LangChain.ChatModels.ChatVertexAI do
5353
alias LangChain.Utils
5454
alias LangChain.Callbacks
5555
alias LangChain.TokenUsage
56+
alias LangChain.NativeTool
57+
alias LangChain.Function
5658

5759
@behaviour ChatModel
5860

@@ -305,6 +307,14 @@ defmodule LangChain.ChatModels.ChatVertexAI do
305307
}
306308
end
307309

310+
defp for_api(%NativeTool{name: name, configuration: %{} = config}) do
311+
%{name => config}
312+
end
313+
314+
defp for_api(%NativeTool{name: name, configuration: nil}) do
315+
name
316+
end
317+
308318
defp for_api(nil), do: nil
309319

310320
@doc """

test/chat_models/chat_vertex_ai_test.exs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,4 +601,32 @@ defmodule ChatModels.ChatVertexAITest do
601601
assert %TokenUsage{input: 7, output: 2} = usage
602602
end
603603
end
604+
605+
describe "google_search native tool" do
606+
@tag live_call: true, live_google_ai: true
607+
test "should include grounding metadata in response" do
608+
alias LangChain.Chains.LLMChain
609+
alias LangChain.Message
610+
alias LangChain.NativeTool
611+
612+
chat =
613+
ChatVertexAI.new!(%{
614+
model: "gemini-2.5-flash",
615+
temperature: 0,
616+
endpoint: System.fetch_env!("VERTEX_API_ENDPOINT"),
617+
stream: true
618+
})
619+
620+
{:ok, updated_chain} =
621+
%{llm: chat, verbose: false, stream: false}
622+
|> LLMChain.new!()
623+
|> LLMChain.add_message(Message.new_user!("What is the current Google stock price?"))
624+
|> LLMChain.add_tools(NativeTool.new!(%{name: "google_search", configuration: %{}}))
625+
|> LLMChain.run()
626+
627+
assert %Message{} = updated_chain.last_message
628+
assert updated_chain.last_message.role == :assistant
629+
assert Map.has_key?(updated_chain.last_message.metadata, "groundingChunks")
630+
end
631+
end
604632
end

0 commit comments

Comments
 (0)