Class: Riffer::Providers::Mock
- Defined in:
- lib/riffer/providers/mock.rb
Overview
Mock provider for mocking LLM responses in tests.
No external gems required.
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Array of recorded method calls for assertions.
Instance Method Summary collapse
-
#clear_stubs ⇒ Object
Clears all stubbed responses.
-
#initialize(**options) ⇒ Mock
constructor
Initializes the mock provider.
-
#stub_response(content, tool_calls: [], token_usage: nil) ⇒ Object
Stubs the next response from the provider.
Methods inherited from Base
#generate_text, skills_adapter, #stream_text
Methods included from Messages::Converter
#convert_to_file_part, #convert_to_message_object
Methods included from Helpers::Dependencies
Constructor Details
#initialize(**options) ⇒ Mock
Initializes the mock provider.
– : (**untyped) -> void
15 16 17 18 19 20 |
# File 'lib/riffer/providers/mock.rb', line 15 def initialize(**) @responses = [:responses] || [] @current_index = 0 @calls = [] @stubbed_responses = [] end |
Instance Attribute Details
#calls ⇒ Object (readonly)
Array of recorded method calls for assertions.
9 10 11 |
# File 'lib/riffer/providers/mock.rb', line 9 def calls @calls end |
Instance Method Details
#clear_stubs ⇒ Object
Clears all stubbed responses.
– : () -> void
47 48 49 |
# File 'lib/riffer/providers/mock.rb', line 47 def clear_stubs @stubbed_responses = [] end |
#stub_response(content, tool_calls: [], token_usage: nil) ⇒ Object
Stubs the next response from the provider.
Can be called multiple times to queue responses.
provider.stub_response("Hello")
provider.stub_response("", tool_calls: [{name: "my_tool", arguments: '{"key":"value"}'}])
provider.stub_response("Final response", token_usage: Riffer::TokenUsage.new(input_tokens: 10, output_tokens: 5))
– : (String, ?tool_calls: Array[Hash[Symbol, untyped]], ?token_usage: Riffer::TokenUsage?) -> void
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/riffer/providers/mock.rb', line 32 def stub_response(content, tool_calls: [], token_usage: nil) formatted_tool_calls = tool_calls.map.with_index do |tc, idx| Riffer::Messages::Assistant::ToolCall.new( call_id: tc[:call_id] || tc[:id] || "mock_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, token_usage: token_usage} end |