Class: RLM::Lm::Mock
- Inherits:
-
Object
- Object
- RLM::Lm::Mock
- Defined in:
- lib/rlm/lm/mock.rb
Instance Attribute Summary collapse
-
#cost_cents ⇒ Object
readonly
Returns the value of attribute cost_cents.
-
#prompts ⇒ Object
readonly
Returns the value of attribute prompts.
Instance Method Summary collapse
- #call(prompt:) ⇒ Object
- #call_count ⇒ Object
-
#initialize(responses:, cost_cents: 0) ⇒ Mock
constructor
A new instance of Mock.
- #last_prompt ⇒ Object
Constructor Details
#initialize(responses:, cost_cents: 0) ⇒ Mock
Returns a new instance of Mock.
8 9 10 11 12 13 14 15 16 |
# File 'lib/rlm/lm/mock.rb', line 8 def initialize(responses:, cost_cents: 0) @responses = Array(responses).dup.freeze raise ArgumentError, "responses must not be empty" if @responses.empty? @cost_cents_per_call = cost_cents @cost_cents = 0 @prompts = [] @index = 0 end |
Instance Attribute Details
#cost_cents ⇒ Object (readonly)
Returns the value of attribute cost_cents.
6 7 8 |
# File 'lib/rlm/lm/mock.rb', line 6 def cost_cents @cost_cents end |
#prompts ⇒ Object (readonly)
Returns the value of attribute prompts.
6 7 8 |
# File 'lib/rlm/lm/mock.rb', line 6 def prompts @prompts end |
Instance Method Details
#call(prompt:) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rlm/lm/mock.rb', line 18 def call(prompt:, **) raise ProviderError, "prompt must be a String" unless prompt.is_a?(String) raise ProviderError, "mock LM responses exhausted" if exhausted? prompts << prompt @cost_cents += @cost_cents_per_call response = @responses.fetch(@index) @index += 1 response end |
#call_count ⇒ Object
30 31 32 |
# File 'lib/rlm/lm/mock.rb', line 30 def call_count prompts.length end |
#last_prompt ⇒ Object
34 35 36 |
# File 'lib/rlm/lm/mock.rb', line 34 def last_prompt prompts.last end |