Class: LLM::Schema
- Inherits:
-
Object
- Object
- LLM::Schema
- Defined in:
- lib/llm/schema.rb,
lib/llm/schema/leaf.rb,
lib/llm/schema/null.rb,
lib/llm/schema/array.rb,
lib/llm/schema/number.rb,
lib/llm/schema/object.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
Classes: Array, Boolean, Integer, Leaf, Null, Number, Object, String
Constant Summary collapse
- VERSION =
-
"0.1.0"
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.
-
#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.
Class Method Details
.property(name, type, description, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/llm/schema.rb', line 61 def self.property(name, type, description, = {}) lock do if LLM::Schema::Leaf === type prop = type elsif Class === type && type.respond_to?(:object) prop = type.object else target = type.name.split("::").last.downcase prop = schema.public_send(target) end = {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.
80 81 82 83 84 |
# File 'lib/llm/schema.rb', line 80 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.
89 90 91 92 93 |
# File 'lib/llm/schema.rb', line 89 def self.object lock do @object ||= schema.object({}) end end |
Instance Method Details
#null ⇒ LLM::Schema::Null
Returns null
149 150 151 |
# File 'lib/llm/schema.rb', line 149 def null Null.new end |
#object(properties) ⇒ LLM::Schema::Object
Returns an object
106 107 108 |
# File 'lib/llm/schema.rb', line 106 def object(properties) Object.new(properties) end |
#array(*items) ⇒ LLM::Schema::Array
Returns an array
114 115 116 |
# File 'lib/llm/schema.rb', line 114 def array(*items) Array.new(*items) end |
#string ⇒ LLM::Schema::String
Returns a string
121 122 123 |
# File 'lib/llm/schema.rb', line 121 def string String.new end |
#number ⇒ LLM::Schema::Number
Returns a number
128 129 130 |
# File 'lib/llm/schema.rb', line 128 def number Number.new end |
#integer ⇒ LLM::Schema::Integer
Returns an integer
135 136 137 |
# File 'lib/llm/schema.rb', line 135 def integer Integer.new end |
#boolean ⇒ LLM::Schema::Boolean
Returns a boolean
142 143 144 |
# File 'lib/llm/schema.rb', line 142 def boolean Boolean.new end |