Class: Braintrust::Contrib::RubyOpenAI::ChatPatcher
- Defined in:
- lib/braintrust/contrib/ruby_openai/patcher.rb
Overview
Patcher for ruby-openai chat completions. Instruments OpenAI::Client#chat method.
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
15 16 17 |
# File 'lib/braintrust/contrib/ruby_openai/patcher.rb', line 15 def applicable? defined?(::OpenAI::Client) end |
.patched?(**options) ⇒ Boolean
19 20 21 22 |
# File 'lib/braintrust/contrib/ruby_openai/patcher.rb', line 19 def patched?(**) target_class = [:target]&.singleton_class || ::OpenAI::Client Instrumentation::Chat.applied?(target_class) end |
.perform_patch(**options) ⇒ void
This method returns an undefined value.
Perform the actual patching.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/braintrust/contrib/ruby_openai/patcher.rb', line 29 def perform_patch(**) return unless applicable? if [:target] # Instance-level (for only this client) raise ArgumentError, "target must be a kind of ::OpenAI::Client" unless [:target].is_a?(::OpenAI::Client) [:target].singleton_class.include(Instrumentation::Chat) else # Class-level (for all clients) ::OpenAI::Client.include(Instrumentation::Chat) end end |