Class: Genai::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/genai/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, base_url: nil, timeout: 60, max_retries: 3) ⇒ Config

Returns a new instance of Config.



8
9
10
11
12
13
14
15
# File 'lib/genai/config.rb', line 8

def initialize(api_key: nil, base_url: nil, timeout: 60, max_retries: 3)
  @api_key = api_key || ENV["GEMINI_API_KEY"]
  @base_url = base_url || "https://generativelanguage.googleapis.com"
  @timeout = timeout
  @max_retries = max_retries
  
  validate_config!
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



6
7
8
# File 'lib/genai/config.rb', line 6

def api_key
  @api_key
end

#base_urlObject

Returns the value of attribute base_url.



6
7
8
# File 'lib/genai/config.rb', line 6

def base_url
  @base_url
end

#max_retriesObject

Returns the value of attribute max_retries.



6
7
8
# File 'lib/genai/config.rb', line 6

def max_retries
  @max_retries
end

#timeoutObject

Returns the value of attribute timeout.



6
7
8
# File 'lib/genai/config.rb', line 6

def timeout
  @timeout
end

Instance Method Details

#api_url(endpoint) ⇒ Object



21
22
23
# File 'lib/genai/config.rb', line 21

def api_url(endpoint)
  "#{@base_url}/v1beta/#{endpoint}"
end

#headersObject



25
26
27
28
29
30
# File 'lib/genai/config.rb', line 25

def headers
  {
    "Content-Type" => "application/json",
    "x-goog-api-key" => @api_key
  }
end

#validate_config!Object

Raises:



17
18
19
# File 'lib/genai/config.rb', line 17

def validate_config!
  raise Error, "API key is required. Set GEMINI_API_KEY environment variable or pass api_key parameter." if @api_key.nil? || @api_key.empty?
end