Class: OpenAI::Helpers::StructuredOutput::ArrayOf

Inherits:
Internal::Type::ArrayOf show all
Includes:
JsonSchemaConverter
Defined in:
lib/openai/helpers/structured_output/array_of.rb

Overview

Examples:

example = OpenAI::ArrayOf[Integer]
example = OpenAI::ArrayOf[Integer, nil?: true, doc: "hi there!"]

Constant Summary

Constants included from JsonSchemaConverter

JsonSchemaConverter::COUNTER, JsonSchemaConverter::POINTER

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JsonSchemaConverter

cache_def!, to_json_schema, to_json_schema_inner, to_nilable

Methods inherited from Internal::Type::ArrayOf

#==, #===, [], #coerce, #dump, #hash, #inspect, #to_sorbet_type

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Methods included from Internal::Type::Converter

#coerce, coerce, #dump, dump, #inspect, inspect, type_info

Constructor Details

#initialize(type_info, spec = {}) ⇒ ArrayOf

Returns a new instance of ArrayOf.



42
43
44
45
# File 'lib/openai/helpers/structured_output/array_of.rb', line 42

def initialize(type_info, spec = {})
  super
  @description = [type_info, spec].grep(Hash).filter_map { _1[:doc] }.first
end

Instance Attribute Details

#descriptionString? (readonly)

Returns:

  • (String, nil)


40
41
42
# File 'lib/openai/helpers/structured_output/array_of.rb', line 40

def description
  @description
end

Instance Method Details

#to_json_schema_inner(state:) ⇒ 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:

  • state (Hash{Symbol=>Object})

    @option state [HashObject=>String] :defs

    @option state [Array<String>] :path

Returns:

  • (Hash{Symbol=>Object})


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/openai/helpers/structured_output/array_of.rb', line 25

def to_json_schema_inner(state:)
  OpenAI::Helpers::StructuredOutput::JsonSchemaConverter.cache_def!(state, type: self) do
    state.fetch(:path) << "[]"
    items = OpenAI::Helpers::StructuredOutput::JsonSchemaConverter.to_json_schema_inner(
      item_type,
      state: state
    )
    items = OpenAI::Helpers::StructuredOutput::JsonSchemaConverter.to_nilable(items) if nilable?

    schema = {type: "array", items: items}
    description.nil? ? schema : schema.update(description: description)
  end
end