View Source LangChain.TokenUsage (LangChain v0.3.3)

Contains token usage information returned from an LLM.

Example

%TokenUsage{
  input: 30,
  output: 15,
  raw: %{
    "total_tokens" => 29
  }
}

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

Refer to the raw token usage information for access to LLM-specific information that may be available.

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(), raw: 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.