Class DefaultUsage

java.lang.Object
org.springframework.ai.chat.metadata.DefaultUsage
All Implemented Interfaces:
Usage

public class DefaultUsage extends Object implements Usage
Default implementation of the Usage interface.
Since:
1.0.0
Author:
Mark Pollack
  • Constructor Details

    • DefaultUsage

      public DefaultUsage(Long promptTokens, Long generationTokens)
      Create a new DefaultUsage with promptTokens and generationTokens.
      Parameters:
      promptTokens - the number of tokens in the prompt, or null if not available
      generationTokens - the number of tokens in the generation, or null if not available
    • DefaultUsage

      public DefaultUsage(Long promptTokens, Long generationTokens, Long totalTokens)
      Create a new DefaultUsage with promptTokens, generationTokens, and totalTokens.
      Parameters:
      promptTokens - the number of tokens in the prompt, or null if not available
      generationTokens - the number of tokens in the generation, or null if not available
      totalTokens - the total number of tokens, or null to calculate from promptTokens and generationTokens
  • Method Details

    • getPromptTokens

      public Long getPromptTokens()
      Description copied from interface: Usage
      Returns the number of tokens used in the prompt of the AI request.
      Specified by:
      getPromptTokens in interface Usage
      Returns:
      an Long with the number of tokens used in the prompt of the AI request.
      See Also:
    • getGenerationTokens

      public Long getGenerationTokens()
      Description copied from interface: Usage
      Returns the number of tokens returned in the generation (aka completion) of the AI's response.
      Specified by:
      getGenerationTokens in interface Usage
      Returns:
      an Long with the number of tokens returned in the generation (aka completion) of the AI's response.
      See Also:
    • getTotalTokens

      public Long getTotalTokens()
      Description copied from interface: Usage
      Return the total number of tokens from both the prompt of an AI request and generation of the AI's response.
      Specified by:
      getTotalTokens in interface Usage
      Returns:
      the total number of tokens from both the prompt of an AI request and generation of the AI's response.
      See Also:
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object