Class: Braintrust::Contrib::RubyOpenAI::ResponsesPatcher
- Defined in:
- lib/braintrust/contrib/ruby_openai/patcher.rb
Overview
Patcher for ruby-openai responses API. Instruments OpenAI::Responses#create 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
49 50 51 |
# File 'lib/braintrust/contrib/ruby_openai/patcher.rb', line 49 def applicable? defined?(::OpenAI::Client) && ::OpenAI::Client.method_defined?(:responses) end |
.patched?(**options) ⇒ Boolean
53 54 55 56 57 58 59 60 61 |
# File 'lib/braintrust/contrib/ruby_openai/patcher.rb', line 53 def patched?(**) if [:target] responses_obj = [:target].responses Instrumentation::Responses.applied?(responses_obj.singleton_class) else # For class-level, check if the responses class is patched defined?(::OpenAI::Responses) && Instrumentation::Responses.applied?(::OpenAI::Responses) end end |
.perform_patch(**options) ⇒ void
This method returns an undefined value.
Perform the actual patching.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/braintrust/contrib/ruby_openai/patcher.rb', line 68 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) responses_obj = [:target].responses responses_obj.singleton_class.include(Instrumentation::Responses) else # Class-level (for all clients) ::OpenAI::Responses.include(Instrumentation::Responses) end end |