Skip to content

Support use of Gemini built-in tools #40

Open
@mathieubrunpicard

Description

@mathieubrunpicard

Hi,

It would be great if the gem would support Gemini's built-in tools like GoogleSearch.

To enable it in the API, the request is as follows:

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=$GOOGLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "contents": [
          {
              "parts": [
                  {"text": "What is the current Google stock price?"}
              ]
          }
      ],
      "tools": [
          {
              "google_search": {}
          }
      ]
  }' > result.json

I was thinking of using it this way

chat = RubyLLM.chat(model: 'gemini-2.0-flash')
chat.with_google_search.ask "What is Google Stock Price Today"

I suggest to update providers/gemini/chat.rb with this method

def with_google_search
          @tools ||= []
    @tools << { google_search: {} }
    self
end

and refacto format_tools in providers/gemini/chat.rb

def format_tools(tools)
  return [] if tools.empty?

  formatted_tools = tools.map do |tool|
    if tool.is_a?(Hash) && tool.key?(:google_search)
      tool  
    else
      {
        functionDeclarations: [function_declaration_for(tool)]
      }
    end
  end

  formatted_tools.flatten
end

What do you think ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions