Record Class TokenCounts

java.lang.Object
java.lang.Record
com.axelor.ai.chat.TokenCounts
Record Components:
input - every prompt token, cached or not
output - every generated token, reasoning included
cacheRead - the part of input served from the provider's cache
cacheWrite - the part of input written to the provider's cache

public record TokenCounts(Integer input, Integer output, Integer cacheRead, Integer cacheWrite) extends Record
A model call's tokens, meaning the same whichever provider served it. Null where the provider did not report the count.
  • Constructor Details

    • TokenCounts

      public TokenCounts(Integer input, Integer output, Integer cacheRead, Integer cacheWrite)
      Creates an instance of a TokenCounts record class.
      Parameters:
      input - the value for the input record component
      output - the value for the output record component
      cacheRead - the value for the cacheRead record component
      cacheWrite - the value for the cacheWrite record component
  • Method Details

    • of

      public static TokenCounts of(dev.langchain4j.model.output.TokenUsage usage)
      Normalizes what LangChain4j reports; no usage reported is no count at all.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • input

      public Integer input()
      Returns the value of the input record component.
      Returns:
      the value of the input record component
    • output

      public Integer output()
      Returns the value of the output record component.
      Returns:
      the value of the output record component
    • cacheRead

      public Integer cacheRead()
      Returns the value of the cacheRead record component.
      Returns:
      the value of the cacheRead record component
    • cacheWrite

      public Integer cacheWrite()
      Returns the value of the cacheWrite record component.
      Returns:
      the value of the cacheWrite record component