View Source LangChain.TokenUsage (LangChain v0.3.0-rc.0)

Contains token usage information returned from an LLM.

Example

%TokenUsage{
  input: 30,
  output: 15
}

Input is the tokens from the prompt. Output is the completion or generated tokens returned.

Summary

Functions

Build a new TokenUsage and return an :ok/:error tuple with the result.

Build a new TokenUsage and return it or raise an error if invalid.

Return the total token usage amount. The total is the sum of input and output.

Types

@type t() :: %LangChain.TokenUsage{input: term(), output: term()}

Functions

@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}

Build a new TokenUsage and return an :ok/:error tuple with the result.

@spec new!(attrs :: map()) :: t() | no_return()

Build a new TokenUsage and return it or raise an error if invalid.

@spec total(t()) :: integer()

Return the total token usage amount. The total is the sum of input and output.