Help us shape the future of Go! Take the 2026 Go Developer Survey

usage

package
v0.1.58 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregator

type Aggregator struct {
	PerModel map[string]*Stat
	// contains filtered or unexported fields
}

Aggregator collects usage grouped by model name.

func FromContext

func FromContext(ctx context.Context) *Aggregator

func WithAggregator

func WithAggregator(ctx context.Context) (context.Context, *Aggregator)

WithAggregator injects Aggregator into context.

func (*Aggregator) Add

func (a *Aggregator) Add(model string, prompt, completion, embed, cached int)

Add records token counts for a specific model. Add records token counts for a specific model. Cached tokens are optional – pass 0 when not applicable.

func (*Aggregator) Keys

func (a *Aggregator) Keys() []string

Keys returns sorted list of model names.

func (*Aggregator) OnUsage

func (a *Aggregator) OnUsage(model string, u *llm.Usage)

OnUsage satisfies provider/base.UsageListener interface allowing Aggregator to be passed directly to provider clients. It records the supplied usage figures under the given model name.

func (*Aggregator) Totals

func (a *Aggregator) Totals() (prompt, completion, embed, cached int)

Totals returns accumulated prompt, completion, embedding and cached tokens across all tracked models. It is primarily intended for tests and reporting.

type Stat

type Stat struct {
	PromptTokens     int
	CompletionTokens int
	EmbeddingTokens  int
	CachedTokens     int
}

Stat accumulates token numbers for a single model.

Jump to

Keyboard shortcuts

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