streamtiming

package
v0.29.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package streamtiming measures arrival of streamed model output at the receiver.

Index

Constants

View Source
const (
	StatusMeasured             = "measured"
	StatusBufferedBurst        = "bufferedBurst"
	StatusHiddenReasoning      = "hiddenReasoning"
	StatusInsufficientEvidence = "insufficientEvidence"
	StatusInterrupted          = "interrupted"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FinalizeInput

type FinalizeInput struct {
	// OutputTokens includes ReasoningTokens. A missing reasoning split is zero.
	OutputTokens, ReasoningTokens int64
	HasUsage, Interrupted         bool
	// EndedAt is the last byte's arrival time. Zero samples the observer clock.
	EndedAt time.Time
}

type Observer

type Observer struct {
	// contains filtered or unexported fields
}

Observer belongs to one stream. Its owner calls the methods serially.

func NewObserver

func NewObserver(now func() time.Time) *Observer

NewObserver starts timing now. Pass nil to use time.Now.

func (*Observer) Finalize

func (o *Observer) Finalize(in FinalizeInput) Snapshot

Finalize returns a detached snapshot. DecodeTokens and DecodeWindowMs describe the candidate interval even when its speed is rejected as a burst.

func (*Observer) MarkHeader

func (o *Observer) MarkHeader()

func (*Observer) ObserveFrame

func (o *Observer) ObserveFrame(protocol Protocol, eventName string, rawJSON []byte)

ObserveFrame accepts the JSON data of one SSE event (or Gemini chunk). Multiple signals in a frame share one arrival and one gap observation.

func (*Observer) ObserveSignal

func (o *Observer) ObserveSignal(kind SignalKind)

ObserveSignal observes a preclassified event. Without payload sizes the concentration check weights each content event equally.

type Protocol

type Protocol string
const (
	ProtocolChat      Protocol = "chat"
	ProtocolResponses Protocol = "responses"
	ProtocolMessages  Protocol = "messages"
	ProtocolGemini    Protocol = "gemini"
)

type SignalKind

type SignalKind uint8
const (
	SignalReasoningStart SignalKind = 1 << iota
	SignalReasoningDelta
	SignalHiddenReasoning
	SignalReasoningSummary
	SignalTextDelta
	SignalToolDelta
)

type Snapshot

type Snapshot struct {
	HeaderMs          *int64   `json:"headerMs"`
	FirstReasoningMs  *int64   `json:"firstReasoningMs"`
	FirstTextMs       *int64   `json:"firstTextMs"`
	LastContentMs     *int64   `json:"lastContentMs"`
	MaxContentGapMs   *int64   `json:"maxContentGapMs"`
	ReasoningEvidence string   `json:"reasoningEvidence"`
	DecodeTokens      int64    `json:"decodeTokens"`
	DecodeWindowMs    *int64   `json:"decodeWindowMs"`
	DecodeTPS         *float64 `json:"decodeTps"`
	DecodeStatus      string   `json:"decodeStatus"`
}

Snapshot owns its values. Missing observations marshal as null, including the maximum gap before two content frames have arrived.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL