Class: RubyLLM::Test::TestProvider
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- RubyLLM::Test::TestProvider
- Extended by:
- Forwardable
- 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 Attribute Summary collapse
-
#complete_calls ⇒ Object
readonly
Returns the value of attribute complete_calls.
Instance Method Summary collapse
-
#complete(messages, tools:, temperature:, model:, params: {}, headers: {}, schema: nil, thinking: nil, tool_prefs: nil, &block) ⇒ Object
rubocop:disable Metrics/ParameterLists.
-
#initialize(provider, test_harness = RubyLLM::Test) ⇒ TestProvider
constructor
A new instance of TestProvider.
- #last_call ⇒ Object
Constructor Details
#initialize(provider, test_harness = RubyLLM::Test) ⇒ TestProvider
Returns a new instance of TestProvider.
16 17 18 19 20 |
# File 'lib/ruby_llm/test/test_provider.rb', line 16 def initialize(provider, test_harness = RubyLLM::Test) super(provider) @test_harness = test_harness @complete_calls = [] end |
Instance Attribute Details
#complete_calls ⇒ Object (readonly)
Returns the value of attribute complete_calls.
11 12 13 |
# File 'lib/ruby_llm/test/test_provider.rb', line 11 def complete_calls @complete_calls end |
Instance Method Details
#complete(messages, tools:, temperature:, model:, params: {}, headers: {}, schema: nil, thinking: nil, tool_prefs: nil, &block) ⇒ Object
rubocop:disable Metrics/ParameterLists
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby_llm/test/test_provider.rb', line 22 def complete(, tools:, temperature:, model:, params: {}, # rubocop:disable Metrics/ParameterLists headers: {}, schema: nil, thinking: nil, tool_prefs: nil, &block) @complete_calls << CompleteParameters.new(messages:, tools:, temperature:, model:, params:, headers:, schema:, thinking:, tool_prefs:, block:) raise Errors::NoResponseProvidedError, 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 |
#last_call ⇒ Object
37 38 39 |
# File 'lib/ruby_llm/test/test_provider.rb', line 37 def last_call @complete_calls.last end |