Class: LLM::Schema::Object

Inherits:
Leaf
  • Object
show all
Defined in:
lib/llm/shell/internal/llm.rb/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) ⇒ Object

Returns a new instance of Object.



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

def initialize(properties)
  @properties = properties
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



10
11
12
# File 'lib/llm/shell/internal/llm.rb/lib/llm/schema/object.rb', line 10

def properties
  @properties
end

Instance Method Details

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

Returns self

Returns:

Raises:

  • (TypeError)

    When given an object other than Object



25
26
27
28
29
# File 'lib/llm/shell/internal/llm.rb/lib/llm/schema/object.rb', line 25

def merge!(other)
  raise TypeError unless self.class === self
  @properties.merge!(other.properties)
  self
end

#to_hObject



16
17
18
# File 'lib/llm/shell/internal/llm.rb/lib/llm/schema/object.rb', line 16

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

#to_json(options = {}) ⇒ Object



31
32
33
# File 'lib/llm/shell/internal/llm.rb/lib/llm/schema/object.rb', line 31

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