Module: Braintrust::Contrib::RubyOpenAI::Instrumentation::Chat
- Defined in:
- lib/braintrust/contrib/ruby_openai/instrumentation/chat.rb
Overview
Chat completions instrumentation for ruby-openai. Provides module that can be prepended to OpenAI::Client to instrument the chat method.
Defined Under Namespace
Modules: InstanceMethods
Constant Summary collapse
- METADATA_FIELDS =
%i[ model frequency_penalty logit_bias logprobs max_tokens n presence_penalty response_format seed service_tier stop stream stream_options temperature top_p top_logprobs tools tool_choice parallel_tool_calls user functions function_call ].freeze
Class Method Summary collapse
Class Method Details
.applied?(base) ⇒ Boolean
28 29 30 |
# File 'lib/braintrust/contrib/ruby_openai/instrumentation/chat.rb', line 28 def self.applied?(base) base.ancestors.include?(InstanceMethods) end |
.included(base) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/braintrust/contrib/ruby_openai/instrumentation/chat.rb', line 18 def self.included(base) # Guard against double-wrapping: Check if patch is already in the ancestor chain. # This prevents double instrumentation if class-level patching was already applied, # and this patch is being applied to a singleton-class. (Special case.) # # Ruby's prepend() doesn't check the full inheritance chain, so without this guard, # the instrumentation could be added twice. base.prepend(InstanceMethods) unless applied?(base) end |