Module: RubyLLM::Schema::DSL::Utilities

Included in:
RubyLLM::Schema::DSL
Defined in:
lib/ruby_llm/schema/dsl/utilities.rb

Instance Method Summary collapse

Instance Method Details

#define(name) ⇒ Object

Schema definition and reference methods



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ruby_llm/schema/dsl/utilities.rb', line 8

def define(name, &)
  sub_schema = Class.new(Schema)
  sub_schema.class_eval(&)

  definitions[name] = {
    type: "object",
    properties: sub_schema.properties,
    required: sub_schema.required_properties,
    additionalProperties: sub_schema.additional_properties
  }
end

#reference(schema_name) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/ruby_llm/schema/dsl/utilities.rb', line 20

def reference(schema_name)
  if schema_name == :root
    {"$ref" => "#"}
  else
    {"$ref" => "#/$defs/#{schema_name}"}
  end
end