Skip to content

Class: TokenMeter

Defined in: evaluator/TokenMeter.ts:4

Tracks the usage of tokens.

Constructors

new TokenMeter()

ts
new TokenMeter(): TokenMeter

Returns

TokenMeter

Accessors

usedInputTokens

Get Signature

ts
get usedInputTokens(): number

Defined in: evaluator/TokenMeter.ts:11

The number of input tokens used

Returns

number


usedOutputTokens

Get Signature

ts
get usedOutputTokens(): number

Defined in: evaluator/TokenMeter.ts:18

The number of tokens generated by a model

Returns

number

Methods

useTokens()

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

Defined in: evaluator/TokenMeter.ts:61

Log the usage of tokens on multiple meters

Parameters

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

Returns

void


diff()

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

Defined in: evaluator/TokenMeter.ts:80

Get the difference between two meters

Parameters

ParameterType
meter1| TokenMeter | TokenMeterState
meter2| TokenMeter | TokenMeterState

Returns

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

getState()

ts
getState(): TokenMeterState

Defined in: evaluator/TokenMeter.ts:25

Get the current state of the token meter

Returns

TokenMeterState


useTokens()

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

Defined in: evaluator/TokenMeter.ts:35

Log the usage of tokens

Parameters

ParameterType
tokensnumber
type"input" | "output"

Returns

void


diff()

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

Defined in: evaluator/TokenMeter.ts:54

Get the difference between the current meter and another meter

Parameters

ParameterType
meter| TokenMeter | TokenMeterState

Returns

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