Skip to content

Google Search Integration with Gemini Models #246

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

florianfelsing
Copy link

@florianfelsing florianfelsing commented Jun 13, 2025

What this does

This PR adds built-in Google Search support for Gemini models by adding a tool under RubyLLM::Providers::Gemini::GoogleSearchTool.

In order to use Google Search with Gemini, use. chat.with_tool(RubyLLM::Providers::Gemini::GoogleSearchTool)

Following up from #49 by @mathieubrunpicard

--

@crmne, we still need to take into account that some Gemini models expect google_search: {} to be present in the payload (e.g. Gemini 2.5 Pro), whereas other models, whereas Gemini 1.5 seems to expect google_search_retrieval.

I still need to account for this differentiation, as well as do some additional testing and add the specs. But I'd appreciate your feedback on whether this PR is going in the direction that you had in mind.

Example Usage

chat = RubyLLM.chat(model: "gemini-2.5-pro-preview-06-05")
chat.ask("What is the current price of BTC?")

Response without GoogleSearchTool

"As an AI, I cannot give you a live, real-time price for Bitcoin (BTC) because its value changes every second. My knowledge
is not connected to live market data.\n\nHowever, you can get the most up-to-the-minute price from any of these reliable sources:\n\n* Google Finance: BTC Price on Google Finance\n* CoinMarketCap: https://coinmarketcap.com/currencies/bitcoin/\n* CoinGecko: https://www.coingecko.com/en/coins/bitcoin\n\nYou can also check the current price on major cryptocurrency exchanges like:\n\n* Coinbase\n* Binance\n* Kraken\n\nThese sites will show you the current price, trading volume, and historical charts."

Response with GoogleSearchTool

"As of Friday, June 13, 2025, the price of Bitcoin (BTC) is fluctuating around the following values:\n\n* $105,022 according to CoinMarketCap.\n* $104,376.57 according to Coinbase.\n* $105,226 according to CoinGecko.\n* $105,570.02 according to Binance.\n* $105,354 according to TradingView.\n\nIt's important to note that the price of Bitcoin is highly volatile and can change rapidly. The price may vary slightly across different cryptocurrency exchanges.\n\nOver the past 24 hours, Bitcoin has seen a slight decline in price, with most sources reporting a decrease of around 1.5% to 2.5%. However, looking at the past week, the price has seen a modest increase of around 0.88% to 1.18%.\n\nThe current market capitalization of Bitcoin is approximately $2.09 trillion. The 24-hour trading volume is significant, with figures ranging from $51.33 billion to over $74 billion.\n\nThe all-time high for Bitcoin was reached on May 21 and 22, 2025, with prices recorded as high as $112,000 and $111,891.30. The total supply of Bitcoin is capped at 21 million coins, with approximately 19.88 million currently in circulation."

Type of change

  • New feature

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

API changes

  • New public methods/classes

Related issues

Related to #40

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