File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff 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 """
Original file line number Diff line number Diff 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
604632end
You can’t perform that action at this time.
0 commit comments