44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package pipeline
|
|
|
|
import "time"
|
|
|
|
type LatencyMetrics struct {
|
|
CallID string
|
|
TurnID string
|
|
TurnStartedAt time.Time
|
|
STTFirstPartialAt time.Time
|
|
STTCommittedAt time.Time
|
|
LLMFirstTokenAt time.Time
|
|
TTSFirstAudioAt time.Time
|
|
FirstAudibleAudioAt time.Time
|
|
CompletedAt time.Time
|
|
STTChars int
|
|
LLMChars int
|
|
TTSAudioBytes int
|
|
Interruptions int
|
|
}
|
|
|
|
func (m LatencyMetrics) Snapshot() map[string]any {
|
|
return map[string]any{
|
|
"call_id": m.CallID,
|
|
"turn_id": m.TurnID,
|
|
"stt_first_partial_ms": sinceMS(m.TurnStartedAt, m.STTFirstPartialAt),
|
|
"stt_committed_ms": sinceMS(m.TurnStartedAt, m.STTCommittedAt),
|
|
"llm_first_token_ms": sinceMS(m.STTCommittedAt, m.LLMFirstTokenAt),
|
|
"tts_first_audio_ms": sinceMS(m.LLMFirstTokenAt, m.TTSFirstAudioAt),
|
|
"first_audible_audio_ms": sinceMS(m.STTCommittedAt, m.FirstAudibleAudioAt),
|
|
"total_turn_ms": sinceMS(m.TurnStartedAt, m.CompletedAt),
|
|
"stt_chars": m.STTChars,
|
|
"llm_chars": m.LLMChars,
|
|
"tts_audio_bytes": m.TTSAudioBytes,
|
|
"interruptions_count": m.Interruptions,
|
|
}
|
|
}
|
|
|
|
func sinceMS(start, end time.Time) any {
|
|
if start.IsZero() || end.IsZero() {
|
|
return nil
|
|
}
|
|
return end.Sub(start).Milliseconds()
|
|
}
|