Class: OmniAI::Google::Client

Inherits:
Client
  • Object
show all
Defined in:
lib/omniai/google/client.rb

Overview

A Google client implementation. Usage:

w/ ‘api_key“:

client = OmniAI::Google::Client.new(api_key: '...')

w/ ENV:

ENV['GOOGLE_API_KEY'] = '...'
client = OmniAI::Google::Client.new

w/ config:

OmniAI::Google.configure do |config|
  config.api_key = '...'
end

client = OmniAI::Google::Client.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: OmniAI::Google.config.api_key, logger: OmniAI::Google.config.logger, host: OmniAI::Google.config.host, version: OmniAI::Google.config.version) ⇒ Client

Returns a new instance of Client.

Parameters:

  • api_key (String) (defaults to: OmniAI::Google.config.api_key)

    optional - defaults to ‘OmniAI::Google.config.api_key`

  • host (String) (defaults to: OmniAI::Google.config.host)

    optional - defaults to ‘OmniAI::Google.config.host`

  • version (String) (defaults to: OmniAI::Google.config.version)

    optional - defaults to ‘OmniAI::Google.config.version`

  • logger (Logger) (defaults to: OmniAI::Google.config.logger)

    optional - defaults to ‘OmniAI::Google.config.logger`

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/omniai/google/client.rb', line 29

def initialize(
  api_key: OmniAI::Google.config.api_key,
  logger: OmniAI::Google.config.logger,
  host: OmniAI::Google.config.host,
  version: OmniAI::Google.config.version
)
  raise(ArgumentError, %(ENV['GOOGLE_API_KEY'] must be defined or `api_key` must be passed)) if api_key.nil?

  super(api_key:, logger:)

  @host = host
  @version = version
end

Instance Attribute Details

#versionObject

Returns the value of attribute version.



23
24
25
# File 'lib/omniai/google/client.rb', line 23

def version
  @version
end

Instance Method Details

#chat(messages, model: Chat::Model::GEMINI_PRO, temperature: nil, format: nil, stream: nil) ⇒ OmniAI::Chat::Completion

Parameters:

  • messages (String, Array, Hash)
  • model (String) (defaults to: Chat::Model::GEMINI_PRO)

    optional

  • format (Symbol) (defaults to: nil)

    optional :text or :json

  • temperature (Float, nil) (defaults to: nil)

    optional

  • stream (Proc, nil) (defaults to: nil)

    optional

Returns:

  • (OmniAI::Chat::Completion)

Raises:

  • (OmniAI::Error)


57
58
59
# File 'lib/omniai/google/client.rb', line 57

def chat(messages, model: Chat::Model::GEMINI_PRO, temperature: nil, format: nil, stream: nil)
  Chat.process!(messages, model:, temperature:, format:, stream:, client: self)
end

#connectionHTTP::Client

Returns:

  • (HTTP::Client)


44
45
46
# File 'lib/omniai/google/client.rb', line 44

def connection
  HTTP.persistent(@host)
end