Class: LlmHub::Common::ClientBase

Inherits:
Object
  • Object
show all
Includes:
HttpHelper
Defined in:
lib/llm_hub/common/client_base.rb

Overview

Base client class for LLM providers Provides common functionality for API clients including HTTP requests, retry logic, and provider initialization

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HttpHelper

#http_client, #http_post

Constructor Details

#initialize(api_key:, provider:, open_time_out: nil, read_time_out: nil, retry_count: nil) ⇒ ClientBase

Initialize a new client

Parameters:

  • api_key (String)

    API key for the provider (required)

  • provider (Symbol, String)

    Provider name (required)

  • open_time_out (Integer) (defaults to: nil)

    HTTP open timeout in seconds (optional, defaults to Config value)

  • read_time_out (Integer) (defaults to: nil)

    HTTP read timeout in seconds (optional, defaults to Config value)

  • retry_count (Integer) (defaults to: nil)

    Number of retries for failed requests (optional, defaults to Config value)



19
20
21
22
23
24
25
# File 'lib/llm_hub/common/client_base.rb', line 19

def initialize(api_key:, provider:, open_time_out: nil, read_time_out: nil, retry_count: nil)
  @api_key = api_key
  @provider = provider
  @open_time_out = open_time_out || LlmHub::Config::DEFAULT_OPEN_TIME_OUT
  @read_time_out = read_time_out || LlmHub::Config::DEFAULT_READ_TIME_OUT
  @retry_count = retry_count || LlmHub::Config::DEFAULT_RETRY_COUNT
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



11
12
13
# File 'lib/llm_hub/common/client_base.rb', line 11

def api_key
  @api_key
end

#open_time_outObject (readonly)

Returns the value of attribute open_time_out.



11
12
13
# File 'lib/llm_hub/common/client_base.rb', line 11

def open_time_out
  @open_time_out
end

#providerObject (readonly)

Returns the value of attribute provider.



11
12
13
# File 'lib/llm_hub/common/client_base.rb', line 11

def provider
  @provider
end

#read_time_outObject (readonly)

Returns the value of attribute read_time_out.



11
12
13
# File 'lib/llm_hub/common/client_base.rb', line 11

def read_time_out
  @read_time_out
end

#retry_countObject (readonly)

Returns the value of attribute retry_count.



11
12
13
# File 'lib/llm_hub/common/client_base.rb', line 11

def retry_count
  @retry_count
end