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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/ruby_llm/providers/gemini/google_search_tool.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module RubyLLM
module Providers
module Gemini
# Marker for Gemini's native Google search
class GoogleSearchTool < RubyLLM::Tool
description 'Gemini built-in Google search capability'

def name = :google_search
def payload = { google_search: {} }
end
end
end
end
13 changes: 10 additions & 3 deletions lib/ruby_llm/providers/gemini/tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ module Tools
def format_tools(tools)
return [] if tools.empty?

[{
functionDeclarations: tools.values.map { |tool| function_declaration_for(tool) }
}]
builtins, customs = tools.values.partition { |t| t.name == :google_search }

formatted_tools = builtins.map(&:payload).uniq
unless customs.empty?
formatted_tools << {
functionDeclarations: customs.map { |t| function_declaration_for(t) }
}
end

formatted_tools
end

# Extract tool calls from response data
Expand Down