Class: Braintrust::Contrib::RubyOpenAI::ModerationsPatcher
- Defined in:
- lib/braintrust/contrib/ruby_openai/patcher.rb
Overview
Patcher for ruby-openai moderations API. Instruments OpenAI::Client#moderations 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
89 90 91 |
# File 'lib/braintrust/contrib/ruby_openai/patcher.rb', line 89 def applicable? defined?(::OpenAI::Client) && ::OpenAI::Client.method_defined?(:moderations) end |
.patched?(**options) ⇒ Boolean
93 94 95 96 |
# File 'lib/braintrust/contrib/ruby_openai/patcher.rb', line 93 def patched?(**) target_class = [:target]&.singleton_class || ::OpenAI::Client Instrumentation::Moderations.applied?(target_class) end |
.perform_patch(**options) ⇒ void
This method returns an undefined value.
Perform the actual patching.
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/braintrust/contrib/ruby_openai/patcher.rb', line 103 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::Moderations) else # Class-level (for all clients) ::OpenAI::Client.include(Instrumentation::Moderations) end end |