ruby_llm-schema 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4706281dcd180f4d6e2b385cc42b79d73629d8eb8a7b5723ddde3b2786a5022e
4
- data.tar.gz: eb083d6fa029a0b107f7a728c86e9f8342a1b9d0c3d0a46d8d4d33adaacd756a
3
+ metadata.gz: 2a5add3bd7f57004c32b88a3fb676370622b0d94931b3e8ad46b2aa021da96f7
4
+ data.tar.gz: 1d371d0595ba66e8e0a31b42f524be07569cf837eb2a044a560cad8f412ea17d
5
5
  SHA512:
6
- metadata.gz: bc52ea4b47664561909278ece104676ae5053572aa791fe6985deb1ecdf40421e49b3b02529ba2a02cbb1df068484d6d162ec0d4c8d525105111ced98451fcbf
7
- data.tar.gz: df555cdab1fb1c786ee0425fb5a1c0dd61bd5ed6c35dfc53bb355cdad27b462c5dbd84cb5d8fb32db6fdbe2c364916f0c8d2ed32565bff87c8ca17b79915ee03
6
+ metadata.gz: e558d54dbe37fde9df32d7c0aa3116d95687e8f1b76e9d6260f10025242671ce67bdb5f44f6020a757dc38ec693e764c11e20388420c6fd65f7ccc7efa391394
7
+ data.tar.gz: d6ba597b33675f573bb3b9d728f128a2bfc431a47e6c87ef2ed37d8c5866a8475eae5f20eb1b670edf31dfd3bdf7d7e79a6329ef68550538930eb4a8aa13030e
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # RubyLLM::Schema
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/ruby_llm-schema.svg)](https://rubygems.org/gems/ruby_llm-schema)
4
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/danielfriis/ruby_llm-schema/blob/main/LICENSE.txt)
5
+ [![CI](https://github.com/danielfriis/ruby_llm-schema/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/danielfriis/ruby_llm-schema/actions/workflows/ci.yml)
6
+
3
7
  A Ruby DSL for creating JSON schemas with a clean, Rails-inspired API. Perfect for defining structured data schemas for LLM function calling or structured outputs.
4
8
 
5
9
  ## Use Cases
@@ -267,9 +271,14 @@ class MySchema < RubyLLM::Schema
267
271
  string :longitude
268
272
  end
269
273
 
274
+ # Using a reference in an array
270
275
  array :coordinates, of: :location
271
-
272
- object :home_location do
276
+
277
+ # Using a reference in an object via the `reference` option
278
+ object :home_location, reference: :location
279
+
280
+ # Using a reference in an object via block
281
+ object :user do
273
282
  reference :location
274
283
  end
275
284
  end
@@ -41,8 +41,8 @@ module RubyLLM
41
41
  end
42
42
 
43
43
  # Complex type methods
44
- def object(name = nil, description: nil, required: true, &block)
45
- add_property(name, build_property_schema(:object, description: description, &block), required: required)
44
+ def object(name = nil, reference: nil, description: nil, required: true, &block)
45
+ add_property(name, build_property_schema(:object, description: description, reference: reference, &block), required: required)
46
46
  end
47
47
 
48
48
  def array(name, of: nil, description: nil, required: true, min_items: nil, max_items: nil, &block)
@@ -123,16 +123,26 @@ module RubyLLM
123
123
  when :null
124
124
  {type: "null", description: options[:description]}.compact
125
125
  when :object
126
+ # If the reference option is provided, return the reference
127
+ return reference(options[:reference]) if options[:reference]
128
+
126
129
  sub_schema = Class.new(Schema)
127
- sub_schema.class_eval(&)
128
130
 
129
- {
130
- type: "object",
131
- properties: sub_schema.properties,
132
- required: sub_schema.required_properties,
133
- additionalProperties: additional_properties,
134
- description: options[:description]
135
- }.compact
131
+ # Evaluate the block and capture the result
132
+ result = sub_schema.class_eval(&)
133
+
134
+ # If the block returned a reference and no properties were added, use the reference
135
+ if result.is_a?(Hash) && result["$ref"] && sub_schema.properties.empty?
136
+ result.merge(options[:description] ? {description: options[:description]} : {})
137
+ else
138
+ {
139
+ type: "object",
140
+ properties: sub_schema.properties,
141
+ required: sub_schema.required_properties,
142
+ additionalProperties: additional_properties,
143
+ description: options[:description]
144
+ }.compact
145
+ end
136
146
  when :any_of
137
147
  schemas = collect_property_schemas_from_block(&)
138
148
  {
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyLlm
4
4
  class Schema
5
- VERSION = "0.1.7"
5
+ VERSION = "0.1.8"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_llm-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Friis