Package dev.langchain4j.model.output
Class TokenUsage
java.lang.Object
dev.langchain4j.model.output.TokenUsage
Represents the token usage of a response.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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.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.
-
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
-