Class: LLM::Response
- Inherits:
-
Object
- Object
- LLM::Response
- Defined in:
- lib/llm/response.rb
Instance Attribute Summary collapse
-
#res ⇒ Net::HTTPResponse
readonly
Returns the HTTP response.
Instance Method Summary collapse
-
#body ⇒ Hash, 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
17 18 19 |
# File 'lib/llm/response.rb', line 17 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)
54 55 56 |
# File 'lib/llm/response.rb', line 54 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
10 11 12 |
# File 'lib/llm/response.rb', line 10 def res @res end |
Instance Method Details
#body ⇒ Hash, String
Returns the response body
24 25 26 27 28 29 |
# File 'lib/llm/response.rb', line 24 def body @body ||= case @res["content-type"] when %r|\Aapplication/json\s*| then LLM::Object.from_hash(JSON.parse(@res.body)) else @res.body end end |
#file? ⇒ Boolean
Returns true if the response is from the Files API
48 49 50 |
# File 'lib/llm/response.rb', line 48 def file? false end |
#inspect ⇒ String
Returns an inspection of the response object
34 35 36 |
# File 'lib/llm/response.rb', line 34 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
41 42 43 |
# File 'lib/llm/response.rb', line 41 def ok? Net::HTTPSuccess === @res end |