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!"]

Generic:

  • Elem

Constant Summary

Constants included from JsonSchemaConverter

JsonSchemaConverter::NO_REF, JsonSchemaConverter::POINTERS

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, new_coerce_state, type_info

Constructor Details

#initialize(type_info, spec = {}) ⇒ 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)



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.



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