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.

Class Method Summary collapse

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

Class Method Details

.display_name ⇒ Object

There are a number of cases that access provider.class.display_name, which avoids the delegation. Adding dummy stub for this. TBD if this needs to be more sophisticated in the future.



16
17
18
# File 'lib/ruby_llm/test/test_provider.rb', line 16

def self.display_name
  "TestProvider"
end

Instance Method Details

#complete ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruby_llm/test/test_provider.rb', line 20

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