Class: RubyLLM::Contract::Adapters::Test
- Defined in:
- lib/ruby_llm/contract/adapters/test.rb
Instance Method Summary collapse
-
#call(messages:, **_options) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#clone_for_concurrency ⇒ Object
Returns a fresh adapter with reset index for concurrent execution.
-
#initialize(response: nil, responses: nil, usage: nil) ⇒ Test
constructor
A new instance of Test.
-
#responses_array ⇒ Object
Exposes raw responses array for concurrent eval to split per-case.
Constructor Details
#initialize(response: nil, responses: nil, usage: nil) ⇒ Test
Returns a new instance of Test.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ruby_llm/contract/adapters/test.rb', line 7 def initialize(response: nil, responses: nil, usage: nil) super() @usage = (usage || { input_tokens: 0, output_tokens: 0 }).dup.freeze if responses raise ArgumentError, "responses: must not be empty (use response: nil for nil content)" if responses.empty? @responses = responses.map { |r| normalize_response(r) } @index = 0 else @response = normalize_response(response) end end |
Instance Method Details
#call(messages:, **_options) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ruby_llm/contract/adapters/test.rb', line 46 def call(messages:, **) # rubocop:disable Lint/UnusedMethodArgument content = if @responses c = @responses[@index] || @responses.last @index += 1 c else @response end Response.new(content: content, usage: @usage) end |
#clone_for_concurrency ⇒ Object
Returns a fresh adapter with reset index for concurrent execution
38 39 40 41 42 43 44 |
# File 'lib/ruby_llm/contract/adapters/test.rb', line 38 def clone_for_concurrency if @responses self.class.new(responses: @responses.dup, usage: @usage.dup) else self.class.new(response: @response, usage: @usage.dup) end end |
#responses_array ⇒ Object
Exposes raw responses array for concurrent eval to split per-case
33 34 35 |
# File 'lib/ruby_llm/contract/adapters/test.rb', line 33 def responses_array @responses end |