Class: Silas::Turn
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Silas::Turn
- Includes:
- Inbox::Broadcastable
- Defined in:
- app/models/silas/turn.rb
Constant Summary collapse
- STATUSES =
%w[queued running waiting in_doubt completed failed canceled].freeze
- ACTIVE_STATUSES =
%w[queued running waiting in_doubt].freeze
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#answer_text ⇒ Object
The agent's answer for this turn: the last completed step's text blocks.
- #completed? ⇒ Boolean
- #finish!(new_status, reason: nil) ⇒ Object
- #parked? ⇒ Boolean
Instance Method Details
#active? ⇒ Boolean
20 |
# File 'app/models/silas/turn.rb', line 20 def active? = ACTIVE_STATUSES.include?(status) |
#answer_text ⇒ Object
The agent's answer for this turn: the last completed step's text blocks.
28 29 30 31 32 33 |
# File 'app/models/silas/turn.rb', line 28 def answer_text step = steps.where(status: "completed").order(:index).last return "" unless step Array(step.response_blocks).select { |b| b["type"] == "text" }.map { |b| b["text"] }.join end |
#completed? ⇒ Boolean
19 |
# File 'app/models/silas/turn.rb', line 19 def completed? = status == "completed" |
#finish!(new_status, reason: nil) ⇒ Object
23 24 25 |
# File 'app/models/silas/turn.rb', line 23 def finish!(new_status, reason: nil) update!(status: new_status.to_s, failure_reason: reason, finished_at: Time.current) end |
#parked? ⇒ Boolean
21 |
# File 'app/models/silas/turn.rb', line 21 def parked? = status == "waiting" || status == "in_doubt" |