Module: RubyLLM::Schema::JsonOutput
- Included in:
- RubyLLM::Schema
- Defined in:
- lib/ruby_llm/schema/json_output.rb
Instance Method Summary collapse
Instance Method Details
#to_json(*_args) ⇒ Object
27 28 29 30 |
# File 'lib/ruby_llm/schema/json_output.rb', line 27 def to_json(*_args) validate! # Validate schema before generating JSON string JSON.pretty_generate(to_json_schema) end |
#to_json_schema ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ruby_llm/schema/json_output.rb', line 6 def to_json_schema validate! # Validate schema before generating JSON schema_hash = { type: "object", properties: self.class.properties, required: self.class.required_properties, additionalProperties: self.class.additional_properties, strict: self.class.strict } # Only include $defs if there are definitions schema_hash["$defs"] = self.class.definitions unless self.class.definitions.empty? { name: @name, description: @description || self.class.description, schema: schema_hash } end |