Class: Braintrust::Contrib::RubyLLM::ChatPatcher
- Defined in:
- lib/braintrust/contrib/ruby_llm/patcher.rb
Overview
Patcher for RubyLLM chat completions. Instruments RubyLLM::Chat#complete and #execute_tool methods.
Class Method Summary collapse
- .applicable? ⇒ Boolean
- .patched?(**options) ⇒ Boolean
-
.perform_patch(**options) ⇒ void
Perform the actual patching.
Methods inherited from Patcher
Class Method Details
.applicable? ⇒ Boolean
13 14 15 |
# File 'lib/braintrust/contrib/ruby_llm/patcher.rb', line 13 def applicable? defined?(::RubyLLM::Chat) end |
.patched?(**options) ⇒ Boolean
17 18 19 20 |
# File 'lib/braintrust/contrib/ruby_llm/patcher.rb', line 17 def patched?(**) target_class = [:target]&.singleton_class || ::RubyLLM::Chat Instrumentation::Chat.applied?(target_class) end |
.perform_patch(**options) ⇒ void
This method returns an undefined value.
Perform the actual patching.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/braintrust/contrib/ruby_llm/patcher.rb', line 27 def perform_patch(**) return unless applicable? if [:target] # Instance-level (for only this chat instance) raise ArgumentError, "target must be a kind of ::RubyLLM::Chat" unless [:target].is_a?(::RubyLLM::Chat) [:target].singleton_class.include(Instrumentation::Chat) else # Class-level (for all chat instances) ::RubyLLM::Chat.include(Instrumentation::Chat) end end |