Class: RubyLLM::Contract::Step::AdapterCaller

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/contract/step/adapter_caller.rb

Instance Method Summary collapse

Constructor Details

#initialize(adapter:, adapter_options:) ⇒ AdapterCaller

Returns a new instance of AdapterCaller.



7
8
9
10
# File 'lib/ruby_llm/contract/step/adapter_caller.rb', line 7

def initialize(adapter:, adapter_options:)
  @adapter = adapter
  @adapter_options = adapter_options
end

Instance Method Details

#call(messages) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/ruby_llm/contract/step/adapter_caller.rb', line 12

def call(messages)
  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  response = @adapter.call(messages: messages, **@adapter_options)
  latency_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round
  [response, latency_ms]
rescue StandardError => error
  [Result.new(status: :adapter_error, raw_output: nil, parsed_output: nil, validation_errors: [error.message]), 0]
end