Class: LLM::Schema
- Inherits:
-
Object
- Object
- LLM::Schema
- Extended by:
- Parser
- Defined in:
- lib/llm/schema.rb,
lib/llm/schema/enum.rb,
lib/llm/schema/leaf.rb,
lib/llm/schema/null.rb,
lib/llm/schema/array.rb,
lib/llm/schema/all_of.rb,
lib/llm/schema/any_of.rb,
lib/llm/schema/number.rb,
lib/llm/schema/object.rb,
lib/llm/schema/one_of.rb,
lib/llm/schema/parser.rb,
lib/llm/schema/string.rb,
lib/llm/schema/boolean.rb,
lib/llm/schema/integer.rb,
lib/llm/schema/version.rb
Overview
The LLM::Schema class represents a JSON schema, and provides methods that let you describe and produce a schema that can be used in various contexts that include the validation and generation of JSON data.
Defined Under Namespace
Modules: Parser, Utils Classes: AllOf, AnyOf, Array, Boolean, Enum, Integer, Leaf, Null, Number, Object, OneOf, String
Constant Summary collapse
- VERSION =
"0.1.0"
Constants included from Parser
Class Method Summary collapse
-
.inherited(klass) ⇒ void
Configures a monitor for a subclass.
- .object ⇒ LLM::Schema::Object private
- .property(name, type, description, options = {}) ⇒ Object
- .schema ⇒ LLM::Schema private
Instance Method Summary collapse
-
#all_of(*values) ⇒ LLM::Schema::AllOf
Returns an allOf union.
-
#any_of(*values) ⇒ LLM::Schema::AnyOf
Returns an anyOf union.
-
#array(*items) ⇒ LLM::Schema::Array
Returns an array.
-
#boolean ⇒ LLM::Schema::Boolean
Returns a boolean.
-
#integer ⇒ LLM::Schema::Integer
Returns an integer.
-
#null ⇒ LLM::Schema::Null
Returns null.
-
#number ⇒ LLM::Schema::Number
Returns a number.
-
#object(properties) ⇒ LLM::Schema::Object
Returns an object.
-
#one_of(*values) ⇒ LLM::Schema::OneOf
Returns a oneOf union.
-
#string ⇒ LLM::Schema::String
Returns a string.
Methods included from Parser
Class Method Details
.inherited(klass) ⇒ void
This method returns an undefined value.
Configures a monitor for a subclass
82 83 84 85 86 |
# File 'lib/llm/schema.rb', line 82 def self.inherited(klass) LLM.lock(:inherited) do klass.instance_eval { @__monitor = Monitor.new } end end |
.object ⇒ LLM::Schema::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.
118 119 120 121 122 |
# File 'lib/llm/schema.rb', line 118 def self.object lock do @object ||= schema.object({}) end end |
.property(name, type, description, options = {}) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/llm/schema.rb', line 97 def self.property(name, type, description, = {}) lock do prop = Utils.resolve(schema, type) = {description:}.merge() .each { (_2 == true) ? prop.public_send(_1) : prop.public_send(_1, *_2) } object[name] = prop end end |
.schema ⇒ LLM::Schema
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.
109 110 111 112 113 |
# File 'lib/llm/schema.rb', line 109 def self.schema lock do @schema ||= LLM::Schema.new end end |
Instance Method Details
#all_of(*values) ⇒ LLM::Schema::AllOf
Returns an allOf union
159 160 161 |
# File 'lib/llm/schema.rb', line 159 def all_of(*values) AllOf.new(values) end |
#any_of(*values) ⇒ LLM::Schema::AnyOf
Returns an anyOf union
151 152 153 |
# File 'lib/llm/schema.rb', line 151 def any_of(*values) AnyOf.new(values) end |
#array(*items) ⇒ LLM::Schema::Array
Returns an array
143 144 145 |
# File 'lib/llm/schema.rb', line 143 def array(*items) Array.new(*items) end |
#boolean ⇒ LLM::Schema::Boolean
Returns a boolean
195 196 197 |
# File 'lib/llm/schema.rb', line 195 def boolean Boolean.new end |
#integer ⇒ LLM::Schema::Integer
Returns an integer
188 189 190 |
# File 'lib/llm/schema.rb', line 188 def integer Integer.new end |
#null ⇒ LLM::Schema::Null
Returns null
202 203 204 |
# File 'lib/llm/schema.rb', line 202 def null Null.new end |
#number ⇒ LLM::Schema::Number
Returns a number
181 182 183 |
# File 'lib/llm/schema.rb', line 181 def number Number.new end |
#object(properties) ⇒ LLM::Schema::Object
Returns an object
135 136 137 |
# File 'lib/llm/schema.rb', line 135 def object(properties) Object.new(properties) end |
#one_of(*values) ⇒ LLM::Schema::OneOf
Returns a oneOf union
167 168 169 |
# File 'lib/llm/schema.rb', line 167 def one_of(*values) OneOf.new(values) end |
#string ⇒ LLM::Schema::String
Returns a string
174 175 176 |
# File 'lib/llm/schema.rb', line 174 def string String.new end |