Class: Boxcars::Google

Inherits:
Openai show all
Defined in:
lib/boxcars/engine/google.rb

Overview

Engine that uses Google’s Gemini OpenAI-compatible API.

Constant Summary collapse

DEFAULT_PARAMS =
{
  model: "gemini-2.5-flash",
  temperature: 0.1,
  max_tokens: 4096
}.freeze
URI_BASE =
"https://generativelanguage.googleapis.com/v1beta/"
DEFAULT_NAME =
"Google Vertex AI engine"
DEFAULT_DESCRIPTION =
"useful for when you need to use Google Vertex AI to process complex content. " \
"Supports text, images, and other content types"

Constants inherited from Openai

Openai::CHAT_MODEL_REGEX, Openai::GPT5_MODEL_REGEX, Openai::O_SERIES_REGEX

Instance Attribute Summary

Attributes inherited from Openai

#open_ai_params

Attributes inherited from Engine

#batch_size, #user_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Openai

#capabilities, #default_params, #validate_response!

Methods inherited from Engine

#add_usage_detail!, #aggregate_generate_usage!, #aggregate_token_usage_details!, #append_generate_choices!, #capabilities, #extract_answer, #generate, #generate_one, #generation_info, #get_num_tokens, #normalize_generate_response, #process_generate_prompt!, #process_generate_response!, #run, #supports?, #usage_nested_token_value, #usage_token_value, #validate_response!

Constructor Details

#initialize(name: DEFAULT_NAME, description: DEFAULT_DESCRIPTION, batch_size: 20, **kwargs) ⇒ Google

Returns a new instance of Google.



18
19
20
# File 'lib/boxcars/engine/google.rb', line 18

def initialize(name: DEFAULT_NAME, description: DEFAULT_DESCRIPTION, batch_size: 20, **kwargs)
  super(name:, description:, batch_size:, **DEFAULT_PARAMS.merge(kwargs))
end

Class Method Details

.provider_client(openai_access_token: nil) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/boxcars/engine/google.rb', line 28

def self.provider_client(openai_access_token: nil)
  access_token = Boxcars.configuration.gemini_api_key(gemini_api_key: openai_access_token)
  Boxcars::OpenAIClient.build(
    access_token:,
    uri_base: URI_BASE
  )
end

Instance Method Details

#client(prompt:, inputs: {}, gemini_api_key: nil, google_api_key: nil) ⇒ Object

Supports both ‘gemini_api_key:` and legacy `google_api_key:` naming.



23
24
25
26
# File 'lib/boxcars/engine/google.rb', line 23

def client(prompt:, inputs: {}, gemini_api_key: nil, google_api_key: nil, **)
  key = gemini_api_key || google_api_key
  super(prompt:, inputs:, openai_access_token: key, **)
end