类 ChatUsage
java.lang.Object
io.agentscope.core.model.ChatUsage
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 ChatUsage.Builderbuilder()Creates a new builder for ChatUsage.intGets the number of input tokens served from the prompt cache.intGets the number of input tokens used.intGets the number of output tokens used.doublegetTime()Gets the execution time.intGets the total number of tokens used.
-
构造器详细资料
-
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)withcachedTokensdefaulting to0.- 参数:
inputTokens- the number of tokens used for the input/promptoutputTokens- the number of tokens used for the output/generated responsetime- 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/promptoutputTokens- the number of tokens used for the output/generated responsecachedTokens- the number of input tokens served from the prompt cache (a subset ofinputTokens);0when the provider does not report cache informationtime- 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. Returns0when 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
Creates a new builder for ChatUsage.- 返回:
- a new Builder instance
-