Class: Raix::ResponseFormat
- Inherits:
-
Object
- Object
- Raix::ResponseFormat
- Defined in:
- lib/raix/response_format.rb
Overview
Handles the formatting of responses for AI interactions.
This class is responsible for converting input data into a JSON schema that can be used to structure and validate AI responses. It supports nested structures and arrays, ensuring that the output conforms to the expected format for AI model interactions.
Instance Attribute Summary collapse
-
#input ⇒ Hash
readonly
The input data to be formatted.
-
#name ⇒ String
readonly
The name of the response format.
Instance Method Summary collapse
-
#initialize(name, input) ⇒ ResponseFormat
constructor
A new instance of ResponseFormat.
- #to_json ⇒ Object
- #to_schema ⇒ Object
Constructor Details
#initialize(name, input) ⇒ ResponseFormat
Returns a new instance of ResponseFormat.
22 23 24 25 |
# File 'lib/raix/response_format.rb', line 22 def initialize(name, input) @name = name @input = input end |
Instance Attribute Details
#input ⇒ Hash (readonly)
The input data to be formatted
21 22 23 |
# File 'lib/raix/response_format.rb', line 21 def input @input end |
#name ⇒ String (readonly)
The name of the response format
21 22 23 |
# File 'lib/raix/response_format.rb', line 21 def name @name end |
Instance Method Details
#to_json ⇒ Object
27 28 29 |
# File 'lib/raix/response_format.rb', line 27 def to_json(*) JSON.pretty_generate(to_schema) end |
#to_schema ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/raix/response_format.rb', line 31 def to_schema { type: "json_schema", json_schema: { name: @name, schema: { type: "object", properties: decode(@input.deep_dup), required: @input.keys, additionalProperties: false }, strict: true } } end |