Class: OpenAI::Internal::RequestOptionsScope Private

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/internal/request_options_scope.rb,
sig/openai/internal/request_options_scope.rbs

Overview

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.

Derives request options for the individual writes in a composite helper.

A caller-supplied idempotency key names the composite operation. Each child write receives a deterministic derived key so its retries remain stable without colliding with another write in the same operation. Structured keys are materialized as the standard header; an explicit header remains authoritative.

Instance Method Summary collapse

Constructor Details

#initialize(request_options) ⇒ RequestOptionsScope

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 RequestOptionsScope.

Parameters:



22
23
24
25
26
27
28
29
30
# File 'lib/openai/internal/request_options_scope.rb', line 22

def initialize(request_options)
  options = request_options.to_h.dup
  OpenAI::RequestOptions.validate!(options)
  if options.key?(:extra_headers)
    options[:extra_headers] = options[:extra_headers].to_h.dup.freeze
  end

  @options = options.freeze
end

Instance Method Details

#child(operation) ⇒ Hash{Symbol=>Object}

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.

Parameters:

  • operation (String)

Returns:

  • (Hash{Symbol=>Object})


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/openai/internal/request_options_scope.rb', line 36

def child(operation)
  options = @options.dup
  key = options[:idempotency_key]
  derived_key = derive(key, operation) unless key.nil?
  options[:idempotency_key] = derived_key unless derived_key.nil?

  headers = options[:extra_headers].to_h
  header = headers.keys.reverse.find { _1.to_s.casecmp?(IDEMPOTENCY_HEADER) }
  header_key = headers[header] unless header.nil?
  if header.nil?
    options[:extra_headers] = headers.merge(IDEMPOTENCY_HEADER => derived_key) unless derived_key.nil?
  elsif !header_key.nil?
    options[:extra_headers] = headers.merge(header => derive(header_key, operation))
  end

  options
end