Aggregated token usage for a run, broken down by stage.
total class-attribute instance-attribute
records class-attribute instance-attribute
by_model class-attribute instance-attribute
by_provider class-attribute instance-attribute
by_kind class-attribute instance-attribute
from_events classmethod
Source code in autogen/beta/usage.py
| @classmethod
def from_events(cls, events: Iterable[BaseEvent]) -> "UsageReport":
records: list[UsageRecord] = []
for event in events:
record = _record_for(event)
if record is not None:
records.append(record)
by_model: dict[str, Usage] = {}
by_provider: dict[str, Usage] = {}
by_kind: dict[str, Usage] = {}
for record in records:
if record.model is not None:
by_model[record.model] = by_model.get(record.model, Usage()) + record.usage
if record.provider is not None:
by_provider[record.provider] = by_provider.get(record.provider, Usage()) + record.usage
by_kind[record.kind] = by_kind.get(record.kind, Usage()) + record.usage
return cls(
total=sum((record.usage for record in records), Usage()),
records=tuple(records),
by_model=by_model,
by_provider=by_provider,
by_kind=by_kind,
)
|