-
-
Notifications
You must be signed in to change notification settings - Fork 106
Initial implementation of google search for Gemini models #49
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
base: main
Are you sure you want to change the base?
Conversation
Cool ! |
def with_google_search | ||
raise UnsupportedFunctionsError, "Model #{@model.id} doesn't support function calling" unless @model.supports_functions | ||
raise UnsupportedFunctionsError, "Google search is only supported with Gemini models" unless @model.provider == 'gemini' | ||
|
||
@tools = [{ | ||
google_search: {} | ||
}] | ||
self | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chat.rb
shouldn't have any code that's provider specific.
I think we should implement a provider overrides API, e.g. .with_provider_overrides({tools: :google_search})
This name is not set in stone, let's discuss naming and implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of :
in lib/ruby_llm/chat.rb
def with_provider_overrides(overrides)
unless @model.supports_functions
raise UnsupportedFunctionsError, "Model #{@model.id} doesn't support function calling"
end
case overrides
when Hash
@tools = @provider.format_provider_overrides(overrides)
when Array
@tools = overrides
else
raise ArgumentError, 'Provider overrides must be a Hash or Array'
end
self
end
and then in gemini.rb
def format_provider_overrides(overrides)
case overrides
when { tools: :google_search }
[{ google_search: {} }]
else
raise ArgumentError, "Unsupported provider override: #{overrides}"
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The best interface IMO would be chat.with_tool(RubyLLM::Providers::Gemini::GoogleSearchTool)
def execute_tool(tool_call) | ||
if tool_call.name.to_sym == :google_search | ||
return tool_call.arguments | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, no provider specific code.
def with_google_search | ||
raise UnsupportedFunctionsError, "Model #{@model.id} doesn't support function calling" unless @model.supports_functions | ||
raise UnsupportedFunctionsError, "Google search is only supported with Gemini models" unless @model.provider == 'gemini' | ||
|
||
@tools = [{ | ||
google_search: {} | ||
}] | ||
self | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The best interface IMO would be chat.with_tool(RubyLLM::Providers::Gemini::GoogleSearchTool)
Google Search Integration with Gemini Models
Issue
Reference: #40
Description
This PR adds built-in Google Search support for Gemini models by introducing a
with_google_search
method to the model.Example Usage
Example response
Example response
Source
Implementation based on: https://ai.google.dev/gemini-api/docs/grounding?lang=rest