Class: LLM::Schema::Deferred Private

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

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.

LLM::Schema::Deferred is a placeholder for a leaf that is resolved when the schema is rendered.

A parameter type that can only be known at runtime - an enum of the keys a store holds right now, for example - is given as a proc. The proc is called when the schema is rendered rather than when the class that declares the parameter is defined, so declaring a tool does not touch whatever the type depends on:

parameter :fruit, proc { Enum[*Fruit.kinds]}, "A fruit", required: true

Whatever the proc returns is resolved in turn, so it can return a leaf, a class, or an array of either.

Instance Attribute Summary

Attributes inherited from Leaf

#index

Instance Method Summary collapse

Methods inherited from Leaf

#==, #const, #default, #description, #enum, #hash, #optional, #optional?, #owner=, #required, #required?, #resolve

Constructor Details

#initialize(&block) ⇒ LLM::Schema::Deferred

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:

  • block (Proc) —

    A block that returns the leaf to resolve to



25
26
27
28
# File 'lib/llm/schema/deferred.rb', line 25

def initialize(&block)
  super()
  @block = block
end

Instance Method Details

#to_h ⇒ Hash

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:

  • (Hash)


32
33
34
# File 'lib/llm/schema/deferred.rb', line 32

def to_h
  resolved_leaf.to_h
end

#to_json(options = {}) ⇒ String

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:

  • options (Hash) (defaults to: {})

Returns:



39
40
41
# File 'lib/llm/schema/deferred.rb', line 39

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

#to_s ⇒ String

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:



45
46
47
# File 'lib/llm/schema/deferred.rb', line 45

def to_s
  resolved_leaf.to_s
end