Skip to content

Class: TokenMeter

Tracks the usage of tokens.

Constructors

new TokenMeter()

ts
new TokenMeter(): TokenMeter

Returns

TokenMeter

Accessors

usedInputTokens

ts
get usedInputTokens(): number

The number of input tokens used

Returns

number

Defined in

evaluator/TokenMeter.ts:11


usedOutputTokens

ts
get usedOutputTokens(): number

The number of tokens generated by a model

Returns

number

Defined in

evaluator/TokenMeter.ts:18

Methods

useTokens()

ts
static useTokens(
   meters: 
  | undefined
  | null
  | TokenMeter
  | ReadonlySet<TokenMeter>
  | readonly TokenMeter[], 
   tokens: number, 
   type: "input" | "output"): void

Log the usage of tokens on multiple meters

Parameters

ParameterType
meters| undefined | null | TokenMeter | ReadonlySet<TokenMeter> | readonly TokenMeter[]
tokensnumber
type"input" | "output"

Returns

void

Defined in

evaluator/TokenMeter.ts:61


diff()

ts
static diff(meter1: TokenMeter | TokenMeterState, meter2: TokenMeter | TokenMeterState): {
  usedInputTokens: number;
  usedOutputTokens: number;
}

Get the difference between two meters

Parameters

ParameterType
meter1TokenMeter | TokenMeterState
meter2TokenMeter | TokenMeterState

Returns

ts
{
  usedInputTokens: number;
  usedOutputTokens: number;
}
usedInputTokens
ts
usedInputTokens: number;
usedOutputTokens
ts
usedOutputTokens: number;

Defined in

evaluator/TokenMeter.ts:80


getState()

ts
getState(): TokenMeterState

Get the current state of the token meter

Returns

TokenMeterState

Defined in

evaluator/TokenMeter.ts:25


useTokens()

ts
useTokens(tokens: number, type: "input" | "output"): void

Log the usage of tokens

Parameters

ParameterType
tokensnumber
type"input" | "output"

Returns

void

Defined in

evaluator/TokenMeter.ts:35


diff()

ts
diff(meter: TokenMeter | TokenMeterState): {
  usedInputTokens: number;
  usedOutputTokens: number;
}

Get the difference between the current meter and another meter

Parameters

ParameterType
meterTokenMeter | TokenMeterState

Returns

ts
{
  usedInputTokens: number;
  usedOutputTokens: number;
}
usedInputTokens
ts
usedInputTokens: number;
usedOutputTokens
ts
usedOutputTokens: number;

Defined in

evaluator/TokenMeter.ts:54