Interface TokenCountEstimator

  • All Implemented Interfaces:

    
    public interface TokenCountEstimator
    
                        

    Represents an interface for estimating the count of tokens in various text types such as a text, message, prompt, text segment, etc. This can be useful when it's necessary to know in advance the cost of processing a specified text by the LLM.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      int estimateTokenCount(String text) Estimates the count of tokens in the specified text.
      int estimateTokenCount(UserMessage userMessage) Estimates the count of tokens in the specified message.
      int estimateTokenCount(Prompt prompt) Estimates the count of tokens in the specified prompt.
      int estimateTokenCount(TextSegment textSegment) Estimates the count of tokens in the specified text segment.
      abstract int estimateTokenCount(List<ChatMessage> messages) Estimates the count of tokens in the specified list of messages.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • estimateTokenCount

         int estimateTokenCount(String text)

        Estimates the count of tokens in the specified text.

        Parameters:
        text - the text
        Returns:

        the estimated count of tokens

      • estimateTokenCount

         int estimateTokenCount(UserMessage userMessage)

        Estimates the count of tokens in the specified message.

        Parameters:
        userMessage - the message
        Returns:

        the estimated count of tokens

      • estimateTokenCount

         int estimateTokenCount(Prompt prompt)

        Estimates the count of tokens in the specified prompt.

        Parameters:
        prompt - the prompt
        Returns:

        the estimated count of tokens

      • estimateTokenCount

         int estimateTokenCount(TextSegment textSegment)

        Estimates the count of tokens in the specified text segment.

        Parameters:
        textSegment - the text segment
        Returns:

        the estimated count of tokens

      • estimateTokenCount

         abstract int estimateTokenCount(List<ChatMessage> messages)

        Estimates the count of tokens in the specified list of messages.

        Parameters:
        messages - the list of messages
        Returns:

        the estimated count of tokens