Class: SolidLoop::Message
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- SolidLoop::Message
- Defined in:
- app/models/solid_loop/message.rb
Instance Method Summary collapse
- #broadcast_update ⇒ Object
- #cumulative_duration ⇒ Object
- #tps ⇒ Object
- #trigger_content_append(new_content, new_reasoning = nil, tool_calls_raw = [], ttft: 0.0, duration_thinking: 0.0, duration_generation: 0.0, tokens_completion: 0) ⇒ Object
Instance Method Details
#broadcast_update ⇒ Object
59 60 61 |
# File 'app/models/solid_loop/message.rb', line 59 def broadcast_update ActiveSupport::Notifications.instrument("solid_loop.message_updated", message: self) end |
#cumulative_duration ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/solid_loop/message.rb', line 32 def cumulative_duration # Sum of generation durations and tool durations for all messages in the loop up to (and including) this one = loop..where("created_at <= ?", created_at) gen_dur = .sum(:duration_generation) # Sum tool durations from tool calls associated with these messages tool_dur = SolidLoop::ToolCall.where(message_id: .map(&:id)).sum(:duration) (gen_dur + tool_dur).round(3) end |
#tps ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/solid_loop/message.rb', line 20 def tps return 0.0 unless tokens_completion.to_i > 0 # Generation time starts from first token until the end # total_duration is duration_generation actual_gen_time = duration_generation.to_f - ttft.to_f return 0.0 if actual_gen_time <= 0 (tokens_completion.to_f / actual_gen_time).round(2) end |
#trigger_content_append(new_content, new_reasoning = nil, tool_calls_raw = [], ttft: 0.0, duration_thinking: 0.0, duration_generation: 0.0, tokens_completion: 0) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/solid_loop/message.rb', line 46 def trigger_content_append(new_content, new_reasoning = nil, tool_calls_raw = [], ttft: 0.0, duration_thinking: 0.0, duration_generation: 0.0, tokens_completion: 0) update_columns( content: new_content, reasoning_content: new_reasoning, tool_calls_raw: tool_calls_raw, ttft: ttft, duration_thinking: duration_thinking, duration_generation: duration_generation, tokens_completion: tokens_completion ) broadcast_update end |