Class: RLM::Lm::RubyLLM
- Inherits:
-
Object
- Object
- RLM::Lm::RubyLLM
- Defined in:
- lib/rlm/lm/ruby_llm.rb
Instance Attribute Summary collapse
-
#call_count ⇒ Object
readonly
Returns the value of attribute call_count.
-
#cost_cents ⇒ Object
readonly
Returns the value of attribute cost_cents.
-
#last_usage ⇒ Object
readonly
Returns the value of attribute last_usage.
Instance Method Summary collapse
- #call(prompt:, signature:, depth:) ⇒ Object
-
#initialize(model: nil, chat_factory: nil) ⇒ RubyLLM
constructor
A new instance of RubyLLM.
Constructor Details
#initialize(model: nil, chat_factory: nil) ⇒ RubyLLM
Returns a new instance of RubyLLM.
10 11 12 13 14 15 16 |
# File 'lib/rlm/lm/ruby_llm.rb', line 10 def initialize(model: nil, chat_factory: nil) @model = model @chat_factory = chat_factory @cost_cents = 0 @last_usage = nil @call_count = 0 end |
Instance Attribute Details
#call_count ⇒ Object (readonly)
Returns the value of attribute call_count.
8 9 10 |
# File 'lib/rlm/lm/ruby_llm.rb', line 8 def call_count @call_count end |
#cost_cents ⇒ Object (readonly)
Returns the value of attribute cost_cents.
8 9 10 |
# File 'lib/rlm/lm/ruby_llm.rb', line 8 def cost_cents @cost_cents end |
#last_usage ⇒ Object (readonly)
Returns the value of attribute last_usage.
8 9 10 |
# File 'lib/rlm/lm/ruby_llm.rb', line 8 def last_usage @last_usage end |
Instance Method Details
#call(prompt:, signature:, depth:) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rlm/lm/ruby_llm.rb', line 18 def call(prompt:, signature:, depth:) raise ProviderError, "prompt must be a String for #{signature} at depth #{depth}" unless prompt.is_a?(String) response = build_chat.ask(prompt) content = response_content(response) cost_delta = response_cost_cents(response) @cost_cents += cost_delta @last_usage = usage_payload(response, cost_delta) @call_count += 1 content rescue ProviderError raise rescue StandardError => e raise ProviderError, "RubyLLM provider call failed: #{e.}" end |