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
- .property(name, type, description, options = {}) ⇒ Object
- .schema ⇒ LLM::Schema private
- .object ⇒ LLM::Schema::Object private
-
.inherited(klass) ⇒
void
Configures a monitor for a subclass.
Instance Method Summary collapse
-
#null ⇒
LLM::Schema::Null
Returns null.
-
#object(properties) ⇒
LLM::Schema::Object
Returns an object.
-
#array(*items) ⇒
LLM::Schema::Array
Returns an array.
-
#any_of(*values) ⇒
LLM::Schema::AnyOf
Returns an anyOf union.
-
#all_of(*values) ⇒
LLM::Schema::AllOf
Returns an allOf union.
-
#one_of(*values) ⇒
LLM::Schema::OneOf
Returns a oneOf union.
-
#string ⇒
LLM::Schema::String
Returns a string.
-
#number ⇒
LLM::Schema::Number
Returns a number.
-
#integer ⇒
LLM::Schema::Integer
Returns an integer.
-
#boolean ⇒
LLM::Schema::Boolean
Returns a boolean.
Methods included from Parser
Class Method Details
.property(name, type, description, options = {}) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/llm/schema.rb', line 86 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.
98 99 100 101 102 |
# File 'lib/llm/schema.rb', line 98 def self.schema lock do @schema ||= LLM::Schema.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.
107 108 109 110 111 |
# File 'lib/llm/schema.rb', line 107 def self.object lock do @object ||= schema.object({}) end end |
Instance Method Details
#null ⇒ LLM::Schema::Null
Returns null
191 192 193 |
# File 'lib/llm/schema.rb', line 191 def null Null.new end |
#object(properties) ⇒ LLM::Schema::Object
Returns an object
124 125 126 |
# File 'lib/llm/schema.rb', line 124 def object(properties) Object.new(properties) end |
#array(*items) ⇒ LLM::Schema::Array
Returns an array
132 133 134 |
# File 'lib/llm/schema.rb', line 132 def array(*items) Array.new(*items) end |
#any_of(*values) ⇒ LLM::Schema::AnyOf
Returns an anyOf union
140 141 142 |
# File 'lib/llm/schema.rb', line 140 def any_of(*values) AnyOf.new(values) end |
#all_of(*values) ⇒ LLM::Schema::AllOf
Returns an allOf union
148 149 150 |
# File 'lib/llm/schema.rb', line 148 def all_of(*values) AllOf.new(values) end |
#one_of(*values) ⇒ LLM::Schema::OneOf
Returns a oneOf union
156 157 158 |
# File 'lib/llm/schema.rb', line 156 def one_of(*values) OneOf.new(values) end |
#string ⇒ LLM::Schema::String
Returns a string
163 164 165 |
# File 'lib/llm/schema.rb', line 163 def string String.new end |
#number ⇒ LLM::Schema::Number
Returns a number
170 171 172 |
# File 'lib/llm/schema.rb', line 170 def number Number.new end |
#integer ⇒ LLM::Schema::Integer
Returns an integer
177 178 179 |
# File 'lib/llm/schema.rb', line 177 def integer Integer.new end |
#boolean ⇒ LLM::Schema::Boolean
Returns a boolean
184 185 186 |
# File 'lib/llm/schema.rb', line 184 def boolean Boolean.new end |