Class: Ace::LLM::Organisms::GoogleClient

Inherits:
BaseClient
  • Object
show all
Defined in:
lib/ace/llm/organisms/google_client.rb

Overview

GoogleClient handles interactions with Google’s Gemini API

Constant Summary collapse

API_BASE_URL =
"https://generativelanguage.googleapis.com"
DEFAULT_MODEL =
"gemini-2.5-flash"
GENERATION_KEY_MAPPING =

Mapping from internal keys to Gemini API camelCase keys

{
  temperature: :temperature,
  max_tokens: :maxOutputTokens,
  top_p: :topP,
  top_k: :topK
}.freeze
DEFAULT_GENERATION_CONFIG =
{
  temperature: 0.7,
  max_tokens: nil,
  top_p: nil,
  top_k: nil
}.freeze

Constants inherited from BaseClient

BaseClient::DEFAULT_SYSTEM_PROMPT_SEPARATOR

Instance Attribute Summary

Attributes inherited from BaseClient

#api_key, #base_url, #generation_config, #http_client, #model

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseClient

#initialize, #needs_credentials?, #provider_name

Constructor Details

This class inherits a constructor from Ace::LLM::Organisms::BaseClient

Class Method Details

.provider_nameString

Get the provider name

Returns:

  • (String)

    Provider name



30
31
32
# File 'lib/ace/llm/organisms/google_client.rb', line 30

def self.provider_name
  "google"
end

Instance Method Details

#generate(messages, **options) ⇒ Hash

Generate a response from Google’s Gemini

Parameters:

  • messages (Array<Hash>, String)

    Messages or prompt

  • options (Hash)

    Generation options

Returns:

  • (Hash)

    Response with text and metadata



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ace/llm/organisms/google_client.rb', line 38

def generate(messages, **options)
  messages_array = build_messages(messages)
  generation_params = extract_generation_options(options)

  request_body = build_request_body(messages_array, generation_params)
  response = make_api_request(request_body)

  parse_response(response)
rescue => e
  handle_api_error(e)
end