Class: LLM::Schema

Inherits:
Object
  • Object
show all
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.

Examples:

schema = LLM::Schema.new
schema.object({
  name: schema.string.enum("John", "Jane").required,
  age: schema.integer.required,
  hobbies: schema.array(schema.string, schema.null).required,
  address: schema.object({street: schema.string}).required,
})

See Also:

Defined Under Namespace

Classes: Array, Boolean, Integer, Leaf, Null, Number, Object, String

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#numberLLM::Schema::Number

Returns a number

Returns:



57
58
59
# File 'lib/llm/schema.rb', line 57

def number
  Number.new
end

#array(*items) ⇒ LLM::Schema::Array

Returns an array

Parameters:

  • items (Array)

    An array of items

Returns:



43
44
45
# File 'lib/llm/schema.rb', line 43

def array(*items)
  Array.new(*items)
end

#stringLLM::Schema::String

Returns a string

Returns:



50
51
52
# File 'lib/llm/schema.rb', line 50

def string
  String.new
end

#object(properties) ⇒ LLM::Schema::Object

Returns an object

Parameters:

  • properties (Hash)

    A hash of properties

Returns:



35
36
37
# File 'lib/llm/schema.rb', line 35

def object(properties)
  Object.new(properties)
end

#integerLLM::Schema::Integer

Returns an integer



64
65
66
# File 'lib/llm/schema.rb', line 64

def integer
  Integer.new
end

#booleanLLM::Schema::Boolean

Returns a boolean



71
72
73
# File 'lib/llm/schema.rb', line 71

def boolean
  Boolean.new
end

#nullLLM::Schema::Null

Returns null

Returns:



78
79
80
# File 'lib/llm/schema.rb', line 78

def null
  Null.new
end