Class: Layered::Assistant::ResponseTimer
- Inherits:
-
Object
- Object
- Layered::Assistant::ResponseTimer
- Defined in:
- app/services/layered/assistant/response_timer.rb
Instance Method Summary collapse
-
#initialize ⇒ ResponseTimer
constructor
A new instance of ResponseTimer.
- #record_first_token! ⇒ Object
- #start! ⇒ Object
- #started? ⇒ Boolean
- #timing_attrs ⇒ Object
Constructor Details
#initialize ⇒ ResponseTimer
Returns a new instance of ResponseTimer.
4 5 6 7 |
# File 'app/services/layered/assistant/response_timer.rb', line 4 def initialize @started_at = nil @first_token_at = nil end |
Instance Method Details
#record_first_token! ⇒ Object
13 14 15 |
# File 'app/services/layered/assistant/response_timer.rb', line 13 def record_first_token! @first_token_at ||= Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
#start! ⇒ Object
9 10 11 |
# File 'app/services/layered/assistant/response_timer.rb', line 9 def start! @started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
#started? ⇒ Boolean
26 27 28 |
# File 'app/services/layered/assistant/response_timer.rb', line 26 def started? !@started_at.nil? end |
#timing_attrs ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/services/layered/assistant/response_timer.rb', line 17 def timing_attrs return {} unless @started_at now = Process.clock_gettime(Process::CLOCK_MONOTONIC) attrs = { response_ms: ((now - @started_at) * 1000).round } attrs[:ttft_ms] = ((@first_token_at - @started_at) * 1000).round if @first_token_at attrs end |