类 ChatUsage

java.lang.Object
io.agentscope.core.model.ChatUsage

public class ChatUsage extends Object
Represents token usage information for chat completion responses.

This immutable data class tracks the number of tokens used during a chat completion, including input tokens (prompt), output tokens (generated response), cached input tokens, and execution time.

  • 嵌套类概要

    嵌套类
    修饰符和类型
    类
    说明
    static class 
    Builder for creating ChatUsage instances.
  • 构造器概要

    构造器
    构造器
    说明
    ChatUsage(int inputTokens, int outputTokens, double time)
    Creates a new ChatUsage instance without cached token information.
    ChatUsage(int inputTokens, int outputTokens, int cachedTokens, double time)
    Creates a new ChatUsage instance.
  • 方法概要

    修饰符和类型
    方法
    说明
    Creates a new builder for ChatUsage.
    int
    Gets the number of input tokens served from the prompt cache.
    int
    Gets the number of input tokens used.
    int
    Gets the number of output tokens used.
    double
    Gets the execution time.
    int
    Gets the total number of tokens used.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • ChatUsage

      public ChatUsage(int inputTokens, int outputTokens, double time)
      Creates a new ChatUsage instance without cached token information.

      This constructor is retained for backward compatibility and delegates to ChatUsage(int, int, int, double) with cachedTokens defaulting to 0.

      参数:
      inputTokens - the number of tokens used for the input/prompt
      outputTokens - the number of tokens used for the output/generated response
      time - the execution time in seconds
    • ChatUsage

      public ChatUsage(int inputTokens, int outputTokens, int cachedTokens, double time)
      Creates a new ChatUsage instance.
      参数:
      inputTokens - the number of tokens used for the input/prompt
      outputTokens - the number of tokens used for the output/generated response
      cachedTokens - the number of input tokens served from the prompt cache (a subset of inputTokens); 0 when the provider does not report cache information
      time - the execution time in seconds
  • 方法详细资料

    • getInputTokens

      public int getInputTokens()
      Gets the number of input tokens used.
      返回:
      the number of tokens used for the input/prompt
    • getOutputTokens

      public int getOutputTokens()
      Gets the number of output tokens used.
      返回:
      the number of tokens used for the output/generated response
    • getCachedTokens

      public int getCachedTokens()
      Gets the number of input tokens served from the prompt cache.

      Cached tokens are a subset of getInputTokens() (i.e. inputTokens = non-cached prompt tokens + cachedTokens), not an additional amount, and are typically billed at a reduced rate. Returns 0 when the provider does not report cache information.

      返回:
      the number of cached input tokens
    • getTotalTokens

      public int getTotalTokens()
      Gets the total number of tokens used.
      返回:
      the sum of input and output tokens
    • getTime

      public double getTime()
      Gets the execution time.
      返回:
      the execution time in seconds
    • builder

      public static ChatUsage.Builder builder()
      Creates a new builder for ChatUsage.
      返回:
      a new Builder instance