Skip to main content

StreamMetrics

Defined in the streaming module.
Rust AI Agent SDK Timing metrics for a streaming response.

Fields

NameTypeDescription
request_startu64Request start time (ms)
headers_receivedu64Headers received time (ms)
first_tokenu64First token time (ms)
last_tokenu64Last token time (ms)
stream_endu64Stream end time (ms)
token_countusizeToken count
start_instantOption<Instant>Internal start instant for precise timing

Methods

new

fn new() -> Self
Create new metrics

ttft_ms

fn ttft_ms(&self) -> u64
Time To First Token in milliseconds

stream_duration_ms

fn stream_duration_ms(&self) -> u64
Stream duration in milliseconds

total_time_ms

fn total_time_ms(&self) -> u64
Total time in milliseconds

tokens_per_second

fn tokens_per_second(&self) -> f64
Tokens per second

update_from_event

fn update_from_event(&mut self, event: &StreamEvent) -> ()
Update metrics from a stream event Parameters:
NameType
event&StreamEvent

mark_request_start

fn mark_request_start(&mut self) -> ()
Mark request start

mark_first_token

fn mark_first_token(&mut self) -> ()
Mark first token

mark_last_token

fn mark_last_token(&mut self) -> ()
Mark last token

mark_stream_end

fn mark_stream_end(&mut self) -> ()
Mark stream end

increment_tokens

fn increment_tokens(&mut self) -> ()
Increment token count

Source

View on GitHub

praisonai/src/streaming/mod.rs at line 242