Class: OmniAI::Google::Config

Inherits:
Config
  • Object
show all
Defined in:
lib/omniai/google/config.rb

Overview

Configuration for Google.

Defined Under Namespace

Modules: Version

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: ENV.fetch("GOOGLE_API_KEY", nil), project_id: ENV.fetch("GOOGLE_PROJECT_ID", nil), location_id: ENV.fetch("GOOGLE_LOCATION_ID", nil), host: ENV.fetch("GOOGLE_HOST", DEFAULT_HOST), logger: nil, timeout: nil) ⇒ Config

Returns a new instance of Config.

Parameters:

  • api_key (String, nil) (defaults to: ENV.fetch("GOOGLE_API_KEY", nil)) —

    optional - defaults to ENV['GOOGLE_API_KEY']

  • project_id (String, nil) (defaults to: ENV.fetch("GOOGLE_PROJECT_ID", nil)) —

    optional - defaults to ENV['GOOGLE_PROJECT_ID']

  • location_id (String, nil) (defaults to: ENV.fetch("GOOGLE_LOCATION_ID", nil)) —

    optional - defaults to ENV['GOOGLE_LOCATION_ID']

  • host (String, nil) (defaults to: ENV.fetch("GOOGLE_HOST", DEFAULT_HOST)) —

    optional - defaults to ENV['GOOGLE_HOST'] w/ fallback to DEFAULT_HOST`

  • version (String, nil) —

    optional - defaults to ENV['GOOGLE_VERSION'] w/ fallback to DEFAULT_VERSION`

  • logger (Logger, nil) (defaults to: nil) —

    optional

  • timeout (Integer, Hash, nil) (defaults to: nil) —

    optional



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/omniai/google/config.rb', line 35

def initialize(
  api_key: ENV.fetch("GOOGLE_API_KEY", nil),
  project_id: ENV.fetch("GOOGLE_PROJECT_ID", nil),
  location_id: ENV.fetch("GOOGLE_LOCATION_ID", nil),
  host: ENV.fetch("GOOGLE_HOST", DEFAULT_HOST),
  logger: nil,
  timeout: nil
)
  super(api_key:, host:, logger:, timeout:)
  @project_id = project_id
  @location_id = location_id
end

Instance Attribute Details

#location_id ⇒ String?

Returns:

  • (String, nil)


20
21
22
# File 'lib/omniai/google/config.rb', line 20

def location_id
  @location_id
end

#locations ⇒ Hash{String => String}?

Vertex location per model, e.g. { "gemini-3.8-flash" => "us" }. When set, each request derives its host from the model's location, and a model missing from the map raises UnknownLocationError.

Returns:

  • (Hash{String => String}, nil)


26
27
28
# File 'lib/omniai/google/config.rb', line 26

def locations
  @locations
end

#project_id ⇒ String?

Returns:

  • (String, nil)


16
17
18
# File 'lib/omniai/google/config.rb', line 16

def project_id
  @project_id
end

Instance Method Details

#credentials ⇒ Google::Auth::ServiceAccountCredentials?

Returns:

  • (Google::Auth::ServiceAccountCredentials, nil)


54
55
56
57
58
# File 'lib/omniai/google/config.rb', line 54

def credentials
  return @credentials if defined?(@credentials)

  Credentials.detect
end

#credentials=(value) ⇒ Object

Parameters:

  • value (String, File, Hash, Google::Auth::ServiceAccountCredentials, nil)


61
62
63
# File 'lib/omniai/google/config.rb', line 61

def credentials=(value)
  @credentials = Credentials.parse(value)
end

#version ⇒ String

Returns:

  • (String)


49
50
51
# File 'lib/omniai/google/config.rb', line 49

def version
  @host.eql?(DEFAULT_HOST) ? Version::BETA : Version::STABLE
end