Class: RubyLLM::Test::TestProvider

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/ruby_llm/test/test_provider.rb

Overview

This class serves as a test double for the provider used in the ‘RubyLLM::Test` class. It captures all calls to

the `complete` method, allowing tests to assert that the correct parameters were passed and to simulate
responses from the provider.

Instance Method Summary collapse

Constructor Details

#initialize(provider, test_harness) ⇒ TestProvider

Returns a new instance of TestProvider.



9
10
11
12
# File 'lib/ruby_llm/test/test_provider.rb', line 9

def initialize(provider, test_harness)
  super(provider)
  @test_harness = test_harness
end

Instance Method Details

#completeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby_llm/test/test_provider.rb', line 14

def complete(...)
  parameters = CompleteParameters.capture_from(__getobj__, ...)
  @test_harness.record_request(parameters)
  raise Errors::NoResponseProvidedError, parameters.messages if @test_harness.responses_empty?

  response = @test_harness.next_response
  return response if response.is_a?(Message)

  Message.new(
    role: :assistant,
    content: response.is_a?(Hash) ? response.to_json : response
  )
end