ruby_llm-schema 0.1.7 → 0.1.9

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: 5965c9d64040358651a74d313d1bd50010378ca33b20ec46a26db8fb006e4e25
4
+ data.tar.gz: a4d9ac3040a6ce33fe0bbc4294166c00e8cafb5e87dcb336d47e1541b504dc12
5
5
  SHA512:
6
- metadata.gz: bc52ea4b47664561909278ece104676ae5053572aa791fe6985deb1ecdf40421e49b3b02529ba2a02cbb1df068484d6d162ec0d4c8d525105111ced98451fcbf
7
- data.tar.gz: df555cdab1fb1c786ee0425fb5a1c0dd61bd5ed6c35dfc53bb355cdad27b462c5dbd84cb5d8fb32db6fdbe2c364916f0c8d2ed32565bff87c8ca17b79915ee03
6
+ metadata.gz: d6ce13ba9d6164a794004fe1138f92ab8d141348d86b33163ad23c119425f252f57b585853ab73a21cff102de9cc403f8936f7b63d4b52d4a572795d8a340aad
7
+ data.tar.gz: 4edbb7d38e7fa1414a812d0fa87f6f20b24e19d2ceb1a151e476c1b330d2e6ac84cfc7faf4aa388858d322bbdaeccffcaa5002db4d19e5a68d5e263876b3db0f
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)
@@ -81,7 +81,8 @@ module RubyLLM
81
81
  definitions[name] = {
82
82
  type: "object",
83
83
  properties: sub_schema.properties,
84
- required: sub_schema.required_properties
84
+ required: sub_schema.required_properties,
85
+ additionalProperties: sub_schema.additional_properties
85
86
  }
86
87
  end
87
88
 
@@ -123,16 +124,26 @@ module RubyLLM
123
124
  when :null
124
125
  {type: "null", description: options[:description]}.compact
125
126
  when :object
127
+ # If the reference option is provided, return the reference
128
+ return reference(options[:reference]) if options[:reference]
129
+
126
130
  sub_schema = Class.new(Schema)
127
- sub_schema.class_eval(&)
128
131
 
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
132
+ # Evaluate the block and capture the result
133
+ result = sub_schema.class_eval(&)
134
+
135
+ # If the block returned a reference and no properties were added, use the reference
136
+ if result.is_a?(Hash) && result["$ref"] && sub_schema.properties.empty?
137
+ result.merge(options[:description] ? {description: options[:description]} : {})
138
+ else
139
+ {
140
+ type: "object",
141
+ properties: sub_schema.properties,
142
+ required: sub_schema.required_properties,
143
+ additionalProperties: sub_schema.additional_properties,
144
+ description: options[:description]
145
+ }.compact
146
+ end
136
147
  when :any_of
137
148
  schemas = collect_property_schemas_from_block(&)
138
149
  {
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyLlm
4
4
  class Schema
5
- VERSION = "0.1.7"
5
+ VERSION = "0.1.9"
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.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Friis