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/number.rb,
lib/llm/schema/object.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 Classes: Array, Boolean, Enum, Integer, Leaf, Null, Number, Object, String
Constant Summary collapse
- VERSION =
"0.1.0"
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
-
#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.
-
#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
51 52 53 54 55 |
# File 'lib/llm/schema.rb', line 51 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.
94 95 96 97 98 |
# File 'lib/llm/schema.rb', line 94 def self.object lock do @object ||= schema.object({}) end end |
.property(name, type, description, options = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/llm/schema.rb', line 66 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.
85 86 87 88 89 |
# File 'lib/llm/schema.rb', line 85 def self.schema lock do @schema ||= LLM::Schema.new end end |
Instance Method Details
#array(*items) ⇒ LLM::Schema::Array
Returns an array
119 120 121 |
# File 'lib/llm/schema.rb', line 119 def array(*items) Array.new(*items) end |
#boolean ⇒ LLM::Schema::Boolean
Returns a boolean
147 148 149 |
# File 'lib/llm/schema.rb', line 147 def boolean Boolean.new end |
#integer ⇒ LLM::Schema::Integer
Returns an integer
140 141 142 |
# File 'lib/llm/schema.rb', line 140 def integer Integer.new end |
#null ⇒ LLM::Schema::Null
Returns null
154 155 156 |
# File 'lib/llm/schema.rb', line 154 def null Null.new end |
#number ⇒ LLM::Schema::Number
Returns a number
133 134 135 |
# File 'lib/llm/schema.rb', line 133 def number Number.new end |
#object(properties) ⇒ LLM::Schema::Object
Returns an object
111 112 113 |
# File 'lib/llm/schema.rb', line 111 def object(properties) Object.new(properties) end |
#string ⇒ LLM::Schema::String
Returns a string
126 127 128 |
# File 'lib/llm/schema.rb', line 126 def string String.new end |