Class: Rails::Llm::Structured::Response
- Inherits:
-
Object
- Object
- Rails::Llm::Structured::Response
- Defined in:
- lib/rails/llm/structured/response.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
-
#initialize(raw_response, schema:) ⇒ Response
constructor
A new instance of Response.
- #method_missing(method, *args) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(raw_response, schema:) ⇒ Response
Returns a new instance of Response.
11 12 13 14 15 16 |
# File 'lib/rails/llm/structured/response.rb', line 11 def initialize(raw_response, schema:) @raw = raw_response @schema = schema @data = parse_response(raw_response) @metadata = (raw_response) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/rails/llm/structured/response.rb', line 18 def method_missing(method, *args) if @data.respond_to?(method) @data.public_send(method, *args) else super end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/rails/llm/structured/response.rb', line 9 def data @data end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/rails/llm/structured/response.rb', line 9 def @metadata end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
9 10 11 |
# File 'lib/rails/llm/structured/response.rb', line 9 def raw @raw end |
Instance Method Details
#respond_to_missing?(method, include_private = false) ⇒ Boolean
26 27 28 |
# File 'lib/rails/llm/structured/response.rb', line 26 def respond_to_missing?(method, include_private = false) @data.respond_to?(method) || super end |
#to_h ⇒ Object
30 31 32 |
# File 'lib/rails/llm/structured/response.rb', line 30 def to_h @data.to_h end |
#valid? ⇒ Boolean
34 35 36 37 38 39 |
# File 'lib/rails/llm/structured/response.rb', line 34 def valid? @schema.validate!(@data.to_h) true rescue false end |