Class UsageUtils

java.lang.Object
org.springframework.ai.chat.metadata.UsageUtils

public class UsageUtils extends Object
An utility class to provide support methods handling Usage.
Author:
Ilayaperumal Gopinathan
  • Constructor Details

    • UsageUtils

      public UsageUtils()
  • Method Details

    • getCumulativeUsage

      public static Usage getCumulativeUsage(Usage currentUsage, ChatResponse previousChatResponse)
      Accumulate usage tokens from the previous chat response to the current usage tokens.
      Parameters:
      currentUsage - the current usage.
      previousChatResponse - the previous chat response.
      Returns:
      accumulated usage.
    • isEmpty

      public static boolean isEmpty(Usage usage)
      Check if the Usage is empty. Returns true when the Usage is null. Returns true when the Usage has zero tokens.
      Parameters:
      usage - the usage to check against.
      Returns:
      the boolean value to represent if it is empty.