Class: RubyPi::LLM::Gemini

Inherits:
BaseProvider show all
Defined in:
lib/ruby_pi/llm/gemini.rb

Overview

Google Gemini provider implementation. Communicates with the Gemini generativelanguage API to generate text completions, handle tool calls, and stream responses.

Examples:

Basic usage

provider = RubyPi::LLM::Gemini.new(
  model: "gemini-2.0-flash",
  api_key: ENV["GEMINI_API_KEY"]
)
response = provider.complete(messages: [{ role: "user", content: "Hello!" }])
puts response.content

Constant Summary collapse

BASE_URL =

Base URL for the Gemini generativelanguage API.

"https://generativelanguage.googleapis.com"
API_VERSION =

API version prefix for endpoint paths.

"v1beta"

Instance Attribute Summary

Attributes inherited from BaseProvider

#max_retries, #retry_base_delay, #retry_max_delay

Instance Method Summary collapse

Methods inherited from BaseProvider

#complete

Constructor Details

#initialize(model: nil, api_key: nil, **options) ⇒ Gemini

Creates a new Gemini provider instance.

Parameters:

  • model (String) (defaults to: nil)

    the Gemini model identifier (e.g., “gemini-2.0-flash”)

  • api_key (String, nil) (defaults to: nil)

    Gemini API key (falls back to global config)

  • options (Hash)

    additional options passed to BaseProvider



34
35
36
37
38
39
# File 'lib/ruby_pi/llm/gemini.rb', line 34

def initialize(model: nil, api_key: nil, **options)
  super(**options)
  config = RubyPi.configuration
  @model = model || config.default_gemini_model
  @api_key = api_key || config.gemini_api_key
end

Instance Method Details

#model_nameString

Returns the Gemini model identifier.

Returns:

  • (String)


44
45
46
# File 'lib/ruby_pi/llm/gemini.rb', line 44

def model_name
  @model
end

#provider_nameSymbol

Returns :gemini as the provider identifier.

Returns:

  • (Symbol)


51
52
53
# File 'lib/ruby_pi/llm/gemini.rb', line 51

def provider_name
  :gemini
end