mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-10 19:29:50 +08:00
fix: 修复缓存 token usage 转换语义
统一 OpenAI、Gemini、Claude 之间缓存 token 的 usage 语义,避免 Claude 侧重复统计缓存输入 token。 同时补充 stream 合并逻辑、字段注释和覆盖转换链路的测试。
This commit is contained in:
@@ -4,6 +4,10 @@ use serde_json::Value;
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct CanonicalUsage {
|
||||
pub input_tokens: u64,
|
||||
/// True when `input_tokens` already includes cache read and cache creation
|
||||
/// input tokens. Claude-style usage leaves cached input tokens separate.
|
||||
#[serde(default, skip_serializing_if = "is_false")]
|
||||
pub input_tokens_include_cache: bool,
|
||||
pub output_tokens: u64,
|
||||
pub total_tokens: u64,
|
||||
pub cache_creation_tokens: u64,
|
||||
@@ -13,6 +17,10 @@ pub struct CanonicalUsage {
|
||||
pub reasoning_tokens: u64,
|
||||
}
|
||||
|
||||
fn is_false(value: &bool) -> bool {
|
||||
!*value
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum CanonicalContentPart {
|
||||
|
||||
Reference in New Issue
Block a user