mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
fix(codex): always include output_tokens_details.reasoning_tokens in … (#3514)
* fix(codex): always include output_tokens_details.reasoning_tokens in chat→responses transform Codex CLI strictly requires reasoning_tokens in the response.completed usage object. Custom providers using /chat/completions often omit completion_tokens_details, causing repeated parse failures and retries. * fix(codex): guard non-object completion_tokens_details before insertion --------- Co-authored-by: yeeyzy <yeeyzy@yangzhiying05@gmail.com>
This commit is contained in:
@@ -801,7 +801,8 @@ impl ChatToResponsesState {
|
|||||||
json!({
|
json!({
|
||||||
"input_tokens": 0,
|
"input_tokens": 0,
|
||||||
"output_tokens": 0,
|
"output_tokens": 0,
|
||||||
"total_tokens": 0
|
"total_tokens": 0,
|
||||||
|
"output_tokens_details": { "reasoning_tokens": 0 }
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1507,7 +1507,8 @@ pub(crate) fn chat_usage_to_responses_usage(usage: Option<&Value>) -> Value {
|
|||||||
return json!({
|
return json!({
|
||||||
"input_tokens": 0,
|
"input_tokens": 0,
|
||||||
"output_tokens": 0,
|
"output_tokens": 0,
|
||||||
"total_tokens": 0
|
"total_tokens": 0,
|
||||||
|
"output_tokens_details": { "reasoning_tokens": 0 }
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1540,8 +1541,17 @@ pub(crate) fn chat_usage_to_responses_usage(usage: Option<&Value>) -> Value {
|
|||||||
result["input_tokens_details"] = json!({ "cached_tokens": cached });
|
result["input_tokens_details"] = json!({ "cached_tokens": cached });
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(details) = usage.get("completion_tokens_details") {
|
if let Some(details) = usage
|
||||||
result["output_tokens_details"] = details.clone();
|
.get("completion_tokens_details")
|
||||||
|
.filter(|v| v.is_object())
|
||||||
|
{
|
||||||
|
let mut details = details.clone();
|
||||||
|
if details.get("reasoning_tokens").is_none() {
|
||||||
|
details["reasoning_tokens"] = json!(0);
|
||||||
|
}
|
||||||
|
result["output_tokens_details"] = details;
|
||||||
|
} else {
|
||||||
|
result["output_tokens_details"] = json!({ "reasoning_tokens": 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(cache_read) = usage.get("cache_read_input_tokens") {
|
if let Some(cache_read) = usage.get("cache_read_input_tokens") {
|
||||||
|
|||||||
Reference in New Issue
Block a user