Documentation
¶
Overview ¶
Package usage decorates an elelem.Driver so every call emits LLM metrics and best-effort persists one llm_usage row.
Index ¶
- func WithAttribution(ctx context.Context, chatID, userID uuid.UUID) context.Context
- func Wrap(inner elelem.Driver, m *metrics.Metrics, stage string, persist bool) elelem.Driver
- type Recorder
- func (r *Recorder) Capabilities(model elelem.Model) elelem.Capabilities
- func (r *Recorder) Complete(ctx context.Context, req elelem.DriverRequest, ...) (elelem.Usage, error)
- func (r *Recorder) ListModels(ctx context.Context) ([]string, error)
- func (r *Recorder) Stream(ctx context.Context, req elelem.DriverRequest, ...) (elelem.Usage, error)
- func (r *Recorder) TokenCounter() elelem.TokenCounter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithAttribution ¶
WithAttribution returns a context carrying the owning chat + user id, so a usage row recorded during a Stream call under this context is attributed to them. The chat loop stamps this before invoking the wrapped client.
Types ¶
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder wraps an elelem.Driver with metrics and usage persistence.
func (*Recorder) Capabilities ¶
func (r *Recorder) Capabilities(model elelem.Model) elelem.Capabilities
Capabilities passes through to the inner driver.
func (*Recorder) Complete ¶
func (r *Recorder) Complete( ctx context.Context, req elelem.DriverRequest, onDelta func(elelem.Delta) error, ) (elelem.Usage, error)
Complete does the same for the non-streaming call, which elelem takes when streaming is off or the provider cannot stream.
It must be recorded identically: the tokens are spent and the row is owed either way, and a decorator that only instrumented Stream would make a backend's usage silently vanish from the metrics the moment someone set WithStreaming(false).
func (*Recorder) ListModels ¶
ListModels passes through to the inner client.
func (*Recorder) Stream ¶
func (r *Recorder) Stream( ctx context.Context, req elelem.DriverRequest, onDelta func(elelem.Delta) error, ) (elelem.Usage, error)
Stream runs the inner streaming call, records metrics + a usage row, and passes the result through unchanged.
func (*Recorder) TokenCounter ¶
func (r *Recorder) TokenCounter() elelem.TokenCounter