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
19
20
21
22
# File 'lib/ruby_llm/schema/dsl/utilities.rb', line 8

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

  schema = {
    type: "object",
    properties: sub_schema.properties,
    required: sub_schema.required_properties,
    additionalProperties: sub_schema.additional_properties
  }

  merge_conditions(schema, sub_schema)

  definitions[name] = schema
end

#reference(schema_name) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/ruby_llm/schema/dsl/utilities.rb', line 24

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