Class: AgentC::Agent::ChatResponse
- Inherits:
-
Object
- Object
- AgentC::Agent::ChatResponse
- Defined in:
- lib/agent_c/agent/chat_response.rb
Instance Attribute Summary collapse
-
#chat_id ⇒ Object
readonly
Returns the value of attribute chat_id.
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
Instance Method Summary collapse
- #data ⇒ Object
- #error_message ⇒ Object
-
#initialize(chat_id:, raw_response:) ⇒ ChatResponse
constructor
A new instance of ChatResponse.
- #status ⇒ Object
- #success? ⇒ Boolean
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_id ⇒ Object (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_response ⇒ Object (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
#data ⇒ Object
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_message ⇒ Object
26 27 28 29 |
# File 'lib/agent_c/agent/chat_response.rb', line 26 def raise "Cannot call error_message on successful response. Use data instead." if success? raw_response.fetch("message") end |
#status ⇒ Object
17 18 19 |
# File 'lib/agent_c/agent/chat_response.rb', line 17 def status @raw_response.fetch("status") end |
#success? ⇒ Boolean
13 14 15 |
# File 'lib/agent_c/agent/chat_response.rb', line 13 def success? status == "success" end |