Package dev.langchain4j.model.output
Class TokenUsage
java.lang.Object
dev.langchain4j.model.output.TokenUsage
- Direct Known Subclasses:
AnthropicTokenUsage
Represents the token usage of a response.
-
Constructor Summary
ConstructorDescriptionCreates a newTokenUsage
instance with all fields set to null.TokenUsage
(Integer inputTokenCount) Creates a newTokenUsage
instance with the given input token count.TokenUsage
(Integer inputTokenCount, Integer outputTokenCount) Creates a newTokenUsage
instance with the given input and output token counts.TokenUsage
(Integer inputTokenCount, Integer outputTokenCount, Integer totalTokenCount) Creates a newTokenUsage
instance with the given input, output and total token counts. -
Method Summary
Modifier and TypeMethodDescriptionadd
(TokenUsage that) Adds the token usage of two responses together.boolean
int
hashCode()
Returns the input token count, or null if unknown.Returns the output token count, or null if unknown.static TokenUsage
sum
(TokenUsage first, TokenUsage second) Adds two token usages.toString()
Returns the total token count, or null if unknown.
-
Constructor Details
-
TokenUsage
public TokenUsage()Creates a newTokenUsage
instance with all fields set to null. -
TokenUsage
Creates a newTokenUsage
instance with the given input token count.- Parameters:
inputTokenCount
- The input token count.
-
TokenUsage
Creates a newTokenUsage
instance with the given input and output token counts.- Parameters:
inputTokenCount
- The input token count, or null if unknown.outputTokenCount
- The output token count, or null if unknown.
-
TokenUsage
Creates a newTokenUsage
instance with the given input, output and total token counts.- Parameters:
inputTokenCount
- The input token count, or null if unknown.outputTokenCount
- The output token count, or null if unknown.totalTokenCount
- The total token count, or null if unknown.
-
-
Method Details
-
inputTokenCount
Returns the input token count, or null if unknown.- Returns:
- the input token count, or null if unknown.
-
outputTokenCount
Returns the output token count, or null if unknown.- Returns:
- the output token count, or null if unknown.
-
totalTokenCount
Returns the total token count, or null if unknown.- Returns:
- the total token count, or null if unknown.
-
sum
Adds two token usages.
If one of the token usages is null, the other is returned without changes.
Fields which are null in both responses will be null in the result.- Parameters:
first
- The first token usage to add.second
- The second token usage to add.- Returns:
- a new
TokenUsage
instance with the sum of token usages.
-
add
Adds the token usage of two responses together.Fields which are null in both responses will be null in the result.
- Parameters:
that
- The token usage to add to this one.- Returns:
- a new
TokenUsage
instance with the token usage of both responses added together.
-
equals
-
hashCode
public int hashCode() -
toString
-