Class: AgentC::Agent::ChatResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_c/agent/chat_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chat_id:, raw_response:) ⇒ ChatResponse

Returns a new instance of ChatResponse.



8
9
10
11
# File 'lib/agent_c/agent/chat_response.rb', line 8

def initialize(chat_id:, raw_response:)
  @chat_id = chat_id
  @raw_response = raw_response
end

Instance Attribute Details

#chat_idObject (readonly)

Returns the value of attribute chat_id.



6
7
8
# File 'lib/agent_c/agent/chat_response.rb', line 6

def chat_id
  @chat_id
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



6
7
8
# File 'lib/agent_c/agent/chat_response.rb', line 6

def raw_response
  @raw_response
end

Instance Method Details

#dataObject



21
22
23
24
# File 'lib/agent_c/agent/chat_response.rb', line 21

def data
  raise "Cannot call data on failed response. Use error_message instead." unless success?
  raw_response.reject { |k, _| k == "status" }
end

#error_messageObject



26
27
28
29
# File 'lib/agent_c/agent/chat_response.rb', line 26

def error_message
  raise "Cannot call error_message on successful response. Use data instead." if success?
  raw_response.fetch("message")
end

#statusObject



17
18
19
# File 'lib/agent_c/agent/chat_response.rb', line 17

def status
  @raw_response.fetch("status")
end

#success?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/agent_c/agent/chat_response.rb', line 13

def success?
  status == "success"
end