Class: Riffer::Providers::Test

Inherits:
Base
  • Object
show all
Defined in:
lib/riffer/providers/test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#generate_text, #stream_text

Methods included from Messages::Converter

#convert_to_message_object

Constructor Details

#initialize(**options) ⇒ Test

Returns a new instance of Test.



6
7
8
9
10
11
# File 'lib/riffer/providers/test.rb', line 6

def initialize(**options)
  @responses = options[:responses] || []
  @current_index = 0
  @calls = []
  @stubbed_responses = []
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



4
5
6
# File 'lib/riffer/providers/test.rb', line 4

def calls
  @calls
end

Instance Method Details

#clear_stubsObject

Clears all stubbed responses



34
35
36
# File 'lib/riffer/providers/test.rb', line 34

def clear_stubs
  @stubbed_responses = []
end

#stub_response(content, tool_calls: []) ⇒ Object

Stubs the next response from the provider Can be called multiple times to queue responses

Examples:

provider.stub_response("Hello")
provider.stub_response("", tool_calls: [{name: "my_tool", arguments: '{"key":"value"}'}])
provider.stub_response("Final response")  # Queued for after tool execution

Parameters:

  • content (String)

    the response content

  • tool_calls (Array<Hash>) (defaults to: [])

    optional tool calls to include



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/riffer/providers/test.rb', line 21

def stub_response(content, tool_calls: [])
  formatted_tool_calls = tool_calls.map.with_index do |tc, idx|
    {
      id: tc[:id] || "test_id_#{idx}",
      call_id: tc[:call_id] || tc[:id] || "test_call_#{idx}",
      name: tc[:name],
      arguments: tc[:arguments].is_a?(String) ? tc[:arguments] : tc[:arguments].to_json
    }
  end
  @stubbed_responses << {role: "assistant", content: content, tool_calls: formatted_tool_calls}
end