Class: OpenAI::Internal::Logging::ObservedBody Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Enumerable[String]
Defined in:
lib/openai/internal/logging.rb,
sig/openai/internal/logging.rbs

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(body:, headers:, context:, attempt:) ⇒ ObservedBody

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ObservedBody.



181
182
183
184
185
186
187
188
189
190
191
# File 'lib/openai/internal/logging.rb', line 181

def initialize(body:, headers:, context:, attempt:)
  @body = body
  @headers = headers
  @context = context
  @attempt = attempt
  @captured = String.new(encoding: Encoding::BINARY)
  @capture_body = OpenAI::Internal::Logging.capture_response_body?(headers)
  @bytes = 0
  @complete = false
  @closed = false
end

Instance Method Details

#closevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/openai/internal/logging.rb', line 209

def close
  return if @closed

  @closed = true
  OpenAI::Internal::Util.close_fused!(@body)
  @context.response_body(
    @captured,
    headers: @headers,
    complete: @complete,
    total_bytes: @bytes,
    attempt: @attempt
  )
end

#each {|arg0| ... } ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (String)

Yield Returns:

  • (void)


193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/openai/internal/logging.rb', line 193

def each
  return enum_for unless block_given?
  return if @closed

  begin
    @body.each do |chunk|
      capture(chunk)
      yield(chunk)
    end

    @complete = true
  ensure
    close
  end
end