Class: SkillBench::Clients::RequestBuilder

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

Overview

Builds and executes HTTP requests to LLM provider APIs. Encapsulates Faraday connection setup and request execution.

Constant Summary collapse

DEFAULT_OPEN_TIMEOUT =
10
DEFAULT_TIMEOUT =
120

Class Method Summary collapse

Class Method Details

.build_connection(base_url, open_timeout: DEFAULT_OPEN_TIMEOUT, timeout: DEFAULT_TIMEOUT) ⇒ Faraday::Connection

Creates a Faraday connection with JSON middleware.

Parameters:

  • base_url (String)

    The API base URL

  • open_timeout (Integer) (defaults to: DEFAULT_OPEN_TIMEOUT)

    Connection open timeout in seconds

  • timeout (Integer) (defaults to: DEFAULT_TIMEOUT)

    Request timeout in seconds

Returns:

  • (Faraday::Connection)

    Configured Faraday connection



19
20
21
22
23
24
25
26
# File 'lib/skill_bench/clients/request_builder.rb', line 19

def self.build_connection(base_url, open_timeout: DEFAULT_OPEN_TIMEOUT, timeout: DEFAULT_TIMEOUT)
  Faraday.new(url: base_url) do |f|
    f.request :json
    f.response :json
    f.options.open_timeout = open_timeout
    f.options.timeout = timeout
  end
end

.execute(connection, path, headers:, body:) ⇒ Faraday::Response

Executes a POST request to the LLM API.

Parameters:

  • connection (Faraday::Connection)

    The Faraday connection

  • path (String)

    The request path

  • headers (Hash)

    Request headers

  • body (Hash)

    Request body

Returns:

  • (Faraday::Response)

    The HTTP response



35
36
37
38
39
40
# File 'lib/skill_bench/clients/request_builder.rb', line 35

def self.execute(connection, path, headers:, body:)
  connection.post(path) do |req|
    req.headers.update(headers)
    req.body = body.to_json
  end
end