Module: RubyLLM::Schema::DSL::SchemaBuilders
- Included in:
- RubyLLM::Schema::DSL
- Defined in:
- lib/ruby_llm/schema/dsl/schema_builders.rb
Instance Method Summary collapse
- #any_of_schema(description: nil, &block) ⇒ Object
- #array_schema(description: nil, of: nil, min_items: nil, max_items: nil, &block) ⇒ Object
- #boolean_schema(description: nil) ⇒ Object
- #integer_schema(description: nil, minimum: nil, maximum: nil, multiple_of: nil) ⇒ Object
- #null_schema(description: nil) ⇒ Object
- #number_schema(description: nil, minimum: nil, maximum: nil, multiple_of: nil) ⇒ Object
- #object_schema(description: nil, of: nil, reference: nil, &block) ⇒ Object
- #one_of_schema(description: nil, &block) ⇒ Object
- #string_schema(description: nil, enum: nil, min_length: nil, max_length: nil, pattern: nil, format: nil) ⇒ Object
Instance Method Details
#any_of_schema(description: nil, &block) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/ruby_llm/schema/dsl/schema_builders.rb', line 92 def any_of_schema(description: nil, &block) schemas = collect_schemas_from_block(&block) { description: description, anyOf: schemas }.compact end |
#array_schema(description: nil, of: nil, min_items: nil, max_items: nil, &block) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ruby_llm/schema/dsl/schema_builders.rb', line 80 def array_schema(description: nil, of: nil, min_items: nil, max_items: nil, &block) items = determine_array_items(of, &block) { type: "array", description: description, items: items, minItems: min_items, maxItems: max_items }.compact end |
#boolean_schema(description: nil) ⇒ Object
39 40 41 |
# File 'lib/ruby_llm/schema/dsl/schema_builders.rb', line 39 def boolean_schema(description: nil) {type: "boolean", description: description}.compact end |
#integer_schema(description: nil, minimum: nil, maximum: nil, multiple_of: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby_llm/schema/dsl/schema_builders.rb', line 29 def integer_schema(description: nil, minimum: nil, maximum: nil, multiple_of: nil) { type: "integer", description: description, minimum: minimum, maximum: maximum, multipleOf: multiple_of }.compact end |
#null_schema(description: nil) ⇒ Object
43 44 45 |
# File 'lib/ruby_llm/schema/dsl/schema_builders.rb', line 43 def null_schema(description: nil) {type: "null", description: description}.compact end |
#number_schema(description: nil, minimum: nil, maximum: nil, multiple_of: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_llm/schema/dsl/schema_builders.rb', line 19 def number_schema(description: nil, minimum: nil, maximum: nil, multiple_of: nil) { type: "number", description: description, minimum: minimum, maximum: maximum, multipleOf: multiple_of }.compact end |
#object_schema(description: nil, of: nil, reference: nil, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruby_llm/schema/dsl/schema_builders.rb', line 47 def object_schema(description: nil, of: nil, reference: nil, &block) if reference warn "[DEPRECATION] The `reference` option will be deprecated. Please use `of` instead." of = reference end if of determine_object_reference(of, description) else sub_schema = Class.new(Schema) result = sub_schema.class_eval(&block) # If the block returned a reference and no properties were added, use the reference if result.is_a?(Hash) && result["$ref"] && sub_schema.properties.empty? result.merge(description ? {description: description} : {}) # If the block returned a Schema class or instance, convert it to inline schema elsif schema_class?(result) && sub_schema.properties.empty? schema_class_to_inline_schema(result).merge(description ? {description: description} : {}) # Block didn't return reference or schema, so we build an inline object schema else schema = { type: "object", properties: sub_schema.properties, required: sub_schema.required_properties, additionalProperties: sub_schema.additional_properties, description: description }.compact merge_conditions(schema, sub_schema) end end end |
#one_of_schema(description: nil, &block) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/ruby_llm/schema/dsl/schema_builders.rb', line 101 def one_of_schema(description: nil, &block) schemas = collect_schemas_from_block(&block) { description: description, oneOf: schemas }.compact end |
#string_schema(description: nil, enum: nil, min_length: nil, max_length: nil, pattern: nil, format: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ruby_llm/schema/dsl/schema_builders.rb', line 7 def string_schema(description: nil, enum: nil, min_length: nil, max_length: nil, pattern: nil, format: nil) { type: "string", enum: enum, description: description, minLength: min_length, maxLength: max_length, pattern: pattern, format: format }.compact end |