Class: LLM::Response
- Inherits:
-
Object
- Object
- LLM::Response
- Defined in:
- lib/llm/response.rb
Overview
LLM::Response encapsulates a response from an LLM provider. It is returned by all methods that make requests to a provider, and sometimes extended with provider-specific functionality.
Instance Attribute Summary collapse
-
#res ⇒ Net::HTTPResponse
readonly
Returns the HTTP response.
Instance Method Summary collapse
-
#body ⇒ LLM::Object, String
Returns the response body.
-
#file? ⇒ Boolean
Returns true if the response is from the Files API.
-
#initialize(res) ⇒ LLM::Response
constructor
Returns an instance of LLM::Response.
-
#inspect ⇒ String
Returns an inspection of the response object.
-
#ok? ⇒ Boolean
Returns true if the response is successful.
Constructor Details
#initialize(res) ⇒ LLM::Response
Returns an instance of LLM::Response
22 23 24 |
# File 'lib/llm/response.rb', line 22 def initialize(res) @res = res end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, **kwargs, &b) ⇒ Object (private)
56 57 58 |
# File 'lib/llm/response.rb', line 56 def method_missing(m, *args, **kwargs, &b) body.respond_to?(m) ? body[m.to_s] : super end |
Instance Attribute Details
#res ⇒ Net::HTTPResponse (readonly)
Returns the HTTP response
15 16 17 |
# File 'lib/llm/response.rb', line 15 def res @res end |
Instance Method Details
#body ⇒ LLM::Object, String
Returns the response body
29 30 31 |
# File 'lib/llm/response.rb', line 29 def body @res.body end |
#file? ⇒ Boolean
Returns true if the response is from the Files API
50 51 52 |
# File 'lib/llm/response.rb', line 50 def file? false end |
#inspect ⇒ String
Returns an inspection of the response object
36 37 38 |
# File 'lib/llm/response.rb', line 36 def inspect "#<#{self.class.name}:0x#{object_id.to_s(16)} @body=#{body.inspect} @res=#{@res.inspect}>" end |
#ok? ⇒ Boolean
Returns true if the response is successful
43 44 45 |
# File 'lib/llm/response.rb', line 43 def ok? Net::HTTPSuccess === @res end |