Class: SkillBench::Clients::BaseClient
- Inherits:
-
Object
- Object
- SkillBench::Clients::BaseClient
- 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.
Direct Known Subclasses
Providers::Anthropic, Providers::AzureOpenAI, Providers::DeepSeek, Providers::Gemini, Providers::Groq, Providers::NullClient, Providers::Ollama, Providers::OpenAI, Providers::OpenCode, Providers::OpenRouter
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#system_prompt ⇒ Object
readonly
Returns the value of attribute system_prompt.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Class Method Summary collapse
-
.call(system_prompt:, messages:, tools: [], **options) ⇒ Hash
Standard entry point for the service object.
Instance Method Summary collapse
-
#call ⇒ Hash
Sends the request to the LLM and returns the standardized response.
-
#initialize(options = {}) ⇒ BaseClient
constructor
Initializes the client with validated parameters.
-
#provider_name ⇒ Symbol
Abstract method to return the provider identifier.
Constructor Details
#initialize(options = {}) ⇒ BaseClient
Initializes the client with validated parameters.
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( = {}) config = ProviderConfig.call(provider: provider_name, 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 = [:system_prompt] || '' @messages = [:messages] || [] @tools = [:tools] || [] end |
Instance Attribute Details
#api_key ⇒ Object (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 |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
16 17 18 |
# File 'lib/skill_bench/clients/base_client.rb', line 16 def @messages end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
16 17 18 |
# File 'lib/skill_bench/clients/base_client.rb', line 16 def model @model end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/skill_bench/clients/base_client.rb', line 16 def @options end |
#system_prompt ⇒ Object (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 |
#tools ⇒ Object (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.
25 26 27 |
# File 'lib/skill_bench/clients/base_client.rb', line 25 def self.call(system_prompt:, messages:, tools: [], **) new(system_prompt: system_prompt, messages: , tools: tools, **).call end |
Instance Method Details
#call ⇒ Hash
Sends the request to the LLM and returns the standardized response.
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_name ⇒ Symbol
Abstract method to return the provider identifier.
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 |