Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add native tool functionality (e.g. google_search for Gemini) #250

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

avergin
Copy link
Contributor

@avergin avergin commented Feb 6, 2025

Adds support for calling native tools like Google Search in Gemini models.

For example, What is the current Google stock price? will return the current stock price.

alias LangChain.Chains.LLMChain
alias LangChain.Message
alias LangChain.NativeTool

model = ChatGoogleAI.new!(%{temperature: 0, stream: false, model: "gemini-2.0-flash"})

{:ok, updated_chain} =
   %{llm: model, verbose: false, stream: false}
   |> LLMChain.new!()
   |> LLMChain.add_message(
     Message.new_user!("What is the current Google stock price?")
   )
   |> LLMChain.add_tools(NativeTool.new!(%{name: "google_search", configuration: %{}}))
   |> LLMChain.run()

I have also added a metadata field (map) to the Message struct to flexibly capture model specific responses when native tools are called. For example when google_search is called, Gemini returns groundingMetadata data, and this can be accessed from metadata.

@avergin avergin marked this pull request as ready for review February 8, 2025 08:54
@avergin
Copy link
Contributor Author

avergin commented Feb 8, 2025

For example, the metadata field in the Message struct may help with capturing the citations data that is returned from Perplexity's API response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant