Module: RubyLLM::Test
- Defined in:
- lib/ruby_llm/test.rb,
lib/ruby_llm/test/version.rb,
lib/ruby_llm/test/test_provider.rb,
lib/ruby_llm/test/complete_parameters.rb,
lib/ruby_llm/test/resolve_with_test_provider.rb,
lib/ruby_llm/test/errors/no_response_provided_error.rb
Overview
The Test module provides a simple way to stub responses from an LLM for testing purposes. You can use it to set up
predetermined responses that your tests can rely on, allowing you to test your code's behavior without making
actual calls to an LLM.
Defined Under Namespace
Modules: Errors, ResolveWithTestProvider
Classes: CompleteParameters, TestProvider
Constant Summary
collapse
- VERSION =
"0.1.0"
Class Method Summary
collapse
Class Method Details
.next_response ⇒ Object
37
38
39
|
# File 'lib/ruby_llm/test.rb', line 37
def next_response
responses.shift
end
|
.reset ⇒ Object
15
16
17
|
# File 'lib/ruby_llm/test.rb', line 15
def reset
@responses = nil
end
|
.responses ⇒ Object
45
46
47
|
# File 'lib/ruby_llm/test.rb', line 45
def responses
@responses ||= []
end
|
.responses_empty? ⇒ Boolean
41
42
43
|
# File 'lib/ruby_llm/test.rb', line 41
def responses_empty?
responses.empty?
end
|
.stub_response(body) ⇒ Object
Pass in a RubyLLM::Message to have full control; strings and hashes will be wrapped in a message
20
21
22
|
# File 'lib/ruby_llm/test.rb', line 20
def stub_response(body)
responses << body
end
|
.stub_responses(*bodies) ⇒ Object
24
25
26
|
# File 'lib/ruby_llm/test.rb', line 24
def stub_responses(*bodies)
responses.concat(bodies)
end
|
.with_responses(*bodies) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/ruby_llm/test.rb', line 28
def with_responses(*bodies)
previous_responses = responses.dup
@responses = []
stub_responses(*bodies)
yield
ensure
@responses = previous_responses
end
|