Class: SkillBench::Clients::BaseClient

Inherits:
Object
  • Object
show all
Defined in:
lib/skill_bench/clients/base_client.rb

Overview

Base class for all LLM provider clients. Orchestrates request execution, response parsing, and error handling. Following the Template Method pattern and ruby-service-objects standards.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BaseClient

Initializes the client with validated parameters.

Parameters:

  • options (Hash) (defaults to: {})

    Configuration overrides.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/skill_bench/clients/base_client.rb', line 31

def initialize(options = {})
  config = ProviderConfig.call(provider: provider_name, options: options)

  @api_key = config[:api_key]
  @model = config[:model]
  @base_url_config = config[:base_url]
  @request_path_config = config[:request_path]
  @provider_display_name = config[:provider_name]

  @location = config[:location]
  @project_id = config[:project_id]
  @endpoint = config[:endpoint]
  @api_version = config[:api_version]

  @system_prompt = options[:system_prompt] || ''
  @messages = options[:messages] || []
  @tools = options[:tools] || []
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



16
17
18
# File 'lib/skill_bench/clients/base_client.rb', line 16

def api_key
  @api_key
end

#messagesObject (readonly)

Returns the value of attribute messages.



16
17
18
# File 'lib/skill_bench/clients/base_client.rb', line 16

def messages
  @messages
end

#modelObject (readonly)

Returns the value of attribute model.



16
17
18
# File 'lib/skill_bench/clients/base_client.rb', line 16

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/skill_bench/clients/base_client.rb', line 16

def options
  @options
end

#system_promptObject (readonly)

Returns the value of attribute system_prompt.



16
17
18
# File 'lib/skill_bench/clients/base_client.rb', line 16

def system_prompt
  @system_prompt
end

#toolsObject (readonly)

Returns the value of attribute tools.



16
17
18
# File 'lib/skill_bench/clients/base_client.rb', line 16

def tools
  @tools
end

Class Method Details

.call(system_prompt:, messages:, tools: [], **options) ⇒ Hash

Standard entry point for the service object.

Parameters:

  • system_prompt (String)

    The system instruction for the LLM.

  • messages (Array<Hash>)

    The list of conversation messages.

  • tools (Array<Hash>) (defaults to: [])

    (optional) Array of tool definitions.

  • options (Hash)

    (optional) Additional provider-specific options.

Returns:

  • (Hash)

    with :success [Boolean] and :response [Hash] keys.



25
26
27
# File 'lib/skill_bench/clients/base_client.rb', line 25

def self.call(system_prompt:, messages:, tools: [], **options)
  new(system_prompt: system_prompt, messages: messages, tools: tools, **options).call
end

Instance Method Details

#callHash

Sends the request to the LLM and returns the standardized response.

Returns:

  • (Hash)

    standardized response with success, body, and usage information.



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/skill_bench/clients/base_client.rb', line 60

def call
  return config_error unless valid_config?

  response = execute_request
  handle_response(response)
rescue Faraday::Error => e
  ResponseErrorHandler.handle_exception(e, 'Network Error')
rescue JSON::ParserError => e
  ResponseErrorHandler.handle_exception(e, 'Parsing Error')
rescue StandardError => e
  ResponseErrorHandler.handle_exception(e, 'Unexpected Error')
end

#provider_nameSymbol

Abstract method to return the provider identifier.

Returns:

  • (Symbol)

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/skill_bench/clients/base_client.rb', line 53

def provider_name
  raise NotImplementedError, "#{self.class} must implement #provider_name"
end