Class: LLM::Schema::Object

Inherits:
Leaf
  • Object
show all
Defined in:
lib/llm/schema/object.rb

Overview

The LLM::Schema::Object class represents an object value in a JSON schema. It is a subclass of LLM::Schema::Leaf and provides methods that can act as constraints.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Leaf

#const, #default, #description, #enum, #required?

Constructor Details

#initialize(properties) ⇒ LLM::Schema::Object

Parameters:

  • params (Hash)

    A hash of properties



18
19
20
# File 'lib/llm/schema/object.rb', line 18

def initialize(properties)
  @properties = properties
end

Instance Attribute Details

#propertiesHash (readonly)

Returns:

  • (Hash)


12
13
14
# File 'lib/llm/schema/object.rb', line 12

def properties
  @properties
end

Instance Method Details

#merge!(other) ⇒ LLM::Schema::Object

Returns self

Returns:

Raises:

  • (TypeError)

    When given an object other than Object



33
34
35
36
37
# File 'lib/llm/schema/object.rb', line 33

def merge!(other)
  raise TypeError, "expected #{self.class} but got #{other.class}" unless self.class === other
  @properties.merge!(other.properties)
  self
end

#to_hHash

Returns:

  • (Hash)


24
25
26
# File 'lib/llm/schema/object.rb', line 24

def to_h
  super.merge!({type: "object", properties:, required:})
end

#to_json(options = {}) ⇒ String

Returns:



41
42
43
# File 'lib/llm/schema/object.rb', line 41

def to_json(options = {})
  to_h.to_json(options)
end