Class: Ollama::Transport::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama/transport/response.rb

Overview

Normalized transport response contract.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, headers:, body:, raw:, duration_ms: nil) ⇒ Response

Returns a new instance of Response.



9
10
11
12
13
14
15
# File 'lib/ollama/transport/response.rb', line 9

def initialize(status:, headers:, body:, raw:, duration_ms: nil)
  @status = status.to_i
  @headers = headers || {}
  @body = body
  @raw = raw
  @duration_ms = duration_ms
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/ollama/transport/response.rb', line 7

def body
  @body
end

#duration_msObject (readonly)

Returns the value of attribute duration_ms.



7
8
9
# File 'lib/ollama/transport/response.rb', line 7

def duration_ms
  @duration_ms
end

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/ollama/transport/response.rb', line 7

def headers
  @headers
end

#rawObject (readonly)

Returns the value of attribute raw.



7
8
9
# File 'lib/ollama/transport/response.rb', line 7

def raw
  @raw
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/ollama/transport/response.rb', line 7

def status
  @status
end

Instance Method Details

#codeObject



32
33
34
# File 'lib/ollama/transport/response.rb', line 32

def code
  status.to_s
end

#is_a?(klass) ⇒ Boolean

Compatibility with existing Net::HTTP response checks

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/ollama/transport/response.rb', line 26

def is_a?(klass)
  return success? if klass == Net::HTTPSuccess

  super
end

#jsonObject



17
18
19
# File 'lib/ollama/transport/response.rb', line 17

def json
  @json ||= JSON.parse(body.to_s)
end

#messageObject



36
37
38
# File 'lib/ollama/transport/response.rb', line 36

def message
  raw.respond_to?(:message) ? raw.message : ""
end

#success?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/ollama/transport/response.rb', line 21

def success?
  status >= 200 && status < 300
end