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.



189
190
191
192
193
194
195
196
197
198
199
# File 'lib/openai/internal/logging.rb', line 189

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.



216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/openai/internal/logging.rb', line 216

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)


201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/openai/internal/logging.rb', line 201

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