ChatUsage
public class ChatUsage
io/agentscope/core/model/ChatUsage.java:28–311聊天用量,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.core.model 包。核心成员包括 getInputTokens、getOutputTokens、getCachedTokens、getCacheCreationTokens、getReasoningTokens、getToolUsePromptTokens。
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), input/output token breakdowns, and execution time.
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | 构建器,用于构建并配置目标实例。 Builder for creating ChatUsage instances. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public ChatUsage(int inputTokens, int outputTokens, double time) | 初始化 `ChatUsage` 实例。 Creates a new ChatUsage instance without token breakdowns. |
public ChatUsage(int inputTokens, int outputTokens, int cachedTokens, double time) | 创建新的ChatUsage 实例。 Creates a new ChatUsage instance. |
public ChatUsage(int inputTokens, int outputTokens, int cachedTokens, int cacheCreationTokens, int reasoningTokens, int toolUsePromptTokens, double time) | 初始化 `ChatUsage` 实例。 Creates a new ChatUsage instance with all token breakdowns. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public int getInputTokens() | 获取输入令牌数。 Gets the number of input tokens used. |
public int getOutputTokens() | 获取输出令牌数。 Gets the number of output tokens used. |
public int getCachedTokens() | 获取已缓存令牌数。 Gets the number of input tokens served from the prompt cache. |
public int getCacheCreationTokens() | 获取 `getCacheCreationTokens`。 Gets the number of input tokens used to create a prompt cache entry. |
public int getReasoningTokens() | 获取推理令牌数。 Gets the number of output tokens used for model reasoning. |
public int getToolUsePromptTokens() | 获取工具使用提示词令牌数。 Gets the number of input tokens representing tool results returned to the model. |
public int getTotalTokens() | 获取总数令牌数。 Gets the total number of tokens used. |
public double getTime() | 获取执行时间。 Gets the execution time. |
public static Builder builder()static | 创建新的构建器用于 ChatUsage。 Creates a new builder for ChatUsage. |
构造器详情Constructor Detail
ChatUsage
public ChatUsage(int inputTokens, int outputTokens, double time)
初始化 ChatUsage 实例。
Creates a new ChatUsage instance without token breakdowns.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
inputTokens | int | 输入令牌数(类型 `int`)。the number of tokens used for the input/prompt |
outputTokens | int | 输出令牌数(类型 `int`)。the number of tokens used for the output/generated response |
time | double | 执行时间 in 秒。the execution time in seconds |
io/agentscope/core/model/ChatUsage.java:48–50ChatUsage
public ChatUsage(int inputTokens, int outputTokens, int cachedTokens, double time)
创建新的ChatUsage 实例。
Creates a new ChatUsage instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
inputTokens | int | 输入令牌数(类型 `int`)。the number of tokens used for the input/prompt |
outputTokens | int | 输出令牌数(类型 `int`)。the number of tokens used for the output/generated response |
cachedTokens | int | 已缓存令牌数(类型 `int`)。the number of input tokens served from the prompt cache (a subset of `inputTokens`); `0` when the provider does not report cache information |
time | double | 执行时间 in 秒。the execution time in seconds |
io/agentscope/core/model/ChatUsage.java:61–67ChatUsage
public ChatUsage(int inputTokens, int outputTokens, int cachedTokens, int cacheCreationTokens, int reasoningTokens, int toolUsePromptTokens, double time)
初始化 ChatUsage 实例。
Creates a new ChatUsage instance with all token breakdowns.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
inputTokens | int | 输入令牌数(类型 `int`)。the number of tokens used for the input/prompt |
outputTokens | int | 输出令牌数(类型 `int`)。the number of tokens used for the output/generated response |
cachedTokens | int | 已缓存令牌数(类型 `int`)。the number of input tokens served from the prompt cache (a subset of `inputTokens`); `0` when the provider does not report cache information |
cacheCreationTokens | int | 缓存 Creation 令牌数(类型 `int`)。the number of input tokens used to create a prompt cache entry (a subset of `inputTokens`); `0` when the provider does not report this information |
reasoningTokens | int | 推理令牌数(类型 `int`)。the number of output tokens used for model reasoning (a subset of `outputTokens`); `0` when the provider does not report this information |
toolUsePromptTokens | int | 工具使用提示词令牌数(类型 `int`)。the number of input tokens representing tool results returned to the model (a subset of `inputTokens`); `0` when the provider does not report this information |
time | double | 执行时间 in 秒。the execution time in seconds |
io/agentscope/core/model/ChatUsage.java:89–105方法详情Method Detail
getInputTokens
public int getInputTokens()
获取输入令牌数。
Gets the number of input tokens used.
intio/agentscope/core/model/ChatUsage.java:112–114getOutputTokens
public int getOutputTokens()
获取输出令牌数。
Gets the number of output tokens used.
intio/agentscope/core/model/ChatUsage.java:121–123getCachedTokens
public int getCachedTokens()
获取已缓存令牌数。
Gets the number of input tokens served from the prompt cache.
intio/agentscope/core/model/ChatUsage.java:134–136getCacheCreationTokens
public int getCacheCreationTokens()
获取 getCacheCreationTokens。
Gets the number of input tokens used to create a prompt cache entry.
intio/agentscope/core/model/ChatUsage.java:147–149getReasoningTokens
public int getReasoningTokens()
获取推理令牌数。
Gets the number of output tokens used for model reasoning.
intio/agentscope/core/model/ChatUsage.java:159–161getToolUsePromptTokens
public int getToolUsePromptTokens()
获取工具使用提示词令牌数。
Gets the number of input tokens representing tool results returned to the model.
intio/agentscope/core/model/ChatUsage.java:171–173getTotalTokens
public int getTotalTokens()
获取总数令牌数。
Gets the total number of tokens used.
intio/agentscope/core/model/ChatUsage.java:180–182getTime
public double getTime()
获取执行时间。
Gets the execution time.
doubleio/agentscope/core/model/ChatUsage.java:189–191builder
public static Builder builder()
创建新的构建器用于 ChatUsage。
Creates a new builder for ChatUsage.
Builderio/agentscope/core/model/ChatUsage.java:198–200嵌套类详情Nested Class Detail
Builder
public static class Builder构建器,用于构建并配置目标实例。位于 io.agentscope.core.model 包。核心成员包括 inputTokens、outputTokens、cachedTokens、cacheCreationTokens、reasoningTokens、toolUsePromptTokens。
Builder for creating ChatUsage instances.