class LittleGhost::Providers::Gemini
Connects a Model to Google’s Gemini generateContent API.
Requests send messages, Tool definitions, attachments, and model settings to the configured Google endpoint. The adapter reads its API key from trusted configuration, honors cancellation and deadlines, and emits LittleGhost StreamEvents. HTTP and response-shape failures become ProviderError subclasses. It uses the built-in HTTP client and does not require Google’s SDK.
Attributes
Provider-owned model identifier.
Public Class Methods
# File lib/little_ghost/providers/gemini.rb, line 30 def initialize(api_key:, model:, base_url: DEFAULT_BASE_URL, open_timeout: 10, read_timeout: 120, max_response_bytes: Support::HTTPClient::DEFAULT_MAX_RESPONSE_BYTES, transport: nil, **) raise CredentialError, "Gemini api_key is required" if api_key.to_s.empty? @api_key = api_key @model = model @transport = transport || Support::HTTPClient.new(base_url:, open_timeout:, read_timeout:, max_response_bytes:) end
Creates a Gemini generateContent client for model.
Source
# File lib/little_ghost/providers/gemini.rb, line 22 def self.request_options = %i[max_response_bytes open_timeout read_timeout].freeze
Request policy supported by Gemini and Vertex AI HTTP clients.
Public Instance Methods
Source
# File lib/little_ghost/providers/gemini.rb, line 61 def capabilities(metadata: {}) ModelCapabilities.new(native_structured_output: true, tools: true, tool_choice: true, supported_parameters: metadata[:supported_parameters]) end
Reports Tool and structured-output support from model metadata.
# File lib/little_ghost/providers/gemini.rb, line 40 def stream(request) return enum_for(__method__, request) unless block_given? parser = Support::SSEParser.new normalizer = Normalizer.new(model:) @transport.stream( path: endpoint, headers: request_headers(request), body: JSON.generate(request_body(request)), cancellation_token: request.cancellation_token, deadline: request.deadline ) do |chunk| parser.<<(chunk).each { |data| normalizer.consume(JSON.parse(data)).each { |event| yield event } } end parser.finish.each { |data| normalizer.consume(JSON.parse(data)).each { |event| yield event } } normalizer.finish.each { |event| yield event } rescue JSON::ParserError => error raise ProtocolError, "Google returned invalid JSON: #{error.message}" end
Streams normalized events for request.