Class: TokenMeter
Tracks the usage of tokens.
Constructors
new TokenMeter()
ts
new TokenMeter(): TokenMeter
Returns
Accessors
usedInputTokens
ts
get usedInputTokens(): number
The number of input tokens used
Returns
number
Defined in
usedOutputTokens
ts
get usedOutputTokens(): number
The number of tokens generated by a model
Returns
number
Defined in
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
Parameter | Type |
---|---|
meters | | undefined | null | TokenMeter | ReadonlySet <TokenMeter > | readonly TokenMeter [] |
tokens | number |
type | "input" | "output" |
Returns
void
Defined in
diff()
ts
static diff(meter1: TokenMeter | TokenMeterState, meter2: TokenMeter | TokenMeterState): {
usedInputTokens: number;
usedOutputTokens: number;
}
Get the difference between two meters
Parameters
Parameter | Type |
---|---|
meter1 | TokenMeter | TokenMeterState |
meter2 | TokenMeter | TokenMeterState |
Returns
ts
{
usedInputTokens: number;
usedOutputTokens: number;
}
usedInputTokens
ts
usedInputTokens: number;
usedOutputTokens
ts
usedOutputTokens: number;
Defined in
getState()
ts
getState(): TokenMeterState
Get the current state of the token meter
Returns
Defined in
useTokens()
ts
useTokens(tokens: number, type: "input" | "output"): void
Log the usage of tokens
Parameters
Parameter | Type |
---|---|
tokens | number |
type | "input" | "output" |
Returns
void
Defined in
diff()
ts
diff(meter: TokenMeter | TokenMeterState): {
usedInputTokens: number;
usedOutputTokens: number;
}
Get the difference between the current meter and another meter
Parameters
Parameter | Type |
---|---|
meter | TokenMeter | TokenMeterState |
Returns
ts
{
usedInputTokens: number;
usedOutputTokens: number;
}
usedInputTokens
ts
usedInputTokens: number;
usedOutputTokens
ts
usedOutputTokens: number;