Class: Genai::Config
- Inherits:
-
Object
- Object
- Genai::Config
- Defined in:
- lib/genai/config.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #api_url(endpoint) ⇒ Object
- #headers ⇒ Object
-
#initialize(api_key: nil, base_url: nil, timeout: 60, max_retries: 3) ⇒ Config
constructor
A new instance of Config.
- #validate_config! ⇒ Object
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_key ⇒ Object
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/genai/config.rb', line 6 def api_key @api_key end |
#base_url ⇒ Object
Returns the value of attribute base_url.
6 7 8 |
# File 'lib/genai/config.rb', line 6 def base_url @base_url end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
6 7 8 |
# File 'lib/genai/config.rb', line 6 def max_retries @max_retries end |
#timeout ⇒ Object
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 |
#headers ⇒ Object
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
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 |