mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-06 17:37:47 +08:00
feat(usage): surface Gemini thinkingConfig as reasoning effort
Usage records show a reasoning badge next to the model name for OpenAI and Claude requests, but Gemini requests never got one. The extraction only read the OpenAI/Claude shapes (`reasoning_effort`, `reasoning.effort`, `output_config.effort`), while Gemini states its reasoning depth inside `generationConfig.thinkingConfig` — so nothing was written to the usage metadata and the list and detail views had no badge to render. Read the Gemini shape too, as a fallback after the existing three so the OpenAI and Claude paths are untouched: - `thinkingLevel` / `thinking_level` wins when present, trimmed and lowercased, with the protobuf enum prefix stripped so `THINKING_LEVEL_HIGH` resolves like `high`. - Otherwise `thinkingBudget` / `thinking_budget` goes through the existing shared budget ladder, yielding the same `low|medium|high|xhigh` vocabulary the badge already understands. - Both camelCase and snake_case spellings are read, so a captured client body and a converted provider body resolve to the same label. - `includeThoughts` alone is a visibility flag, not a depth, and produces no badge. Two cases are handled explicitly rather than through the shared ladder: - `thinkingBudget: 0` disables reasoning outright. The shared ladder maps `0..=1664` to `low`, which would report an explicitly disabled request as a shallow one, so it reports `none` instead. - `THINKING_LEVEL_UNSPECIFIED` is the enum's "no explicit level" member, not a depth; it is rejected rather than surfaced as an `unspecified` badge. The frontend needs no change: `UsageModelDisplay` already renders the badge whenever the fields are present, and keeps the `high -> xhigh` mapping format when the requested and upstream efforts differ.
This commit is contained in:
@@ -663,6 +663,39 @@ mod tests {
|
||||
assert!(cleared.get("requested_reasoning_effort").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gemini_thinking_config_is_derived_into_client_and_provider_reasoning_metadata() {
|
||||
let client_body = json!({
|
||||
"generationConfig": {
|
||||
"thinkingConfig": { "includeThoughts": true, "thinkingLevel": "HIGH" }
|
||||
}
|
||||
});
|
||||
let provider_body = json!({
|
||||
"generation_config": {
|
||||
"thinking_config": { "thinking_budget": 8192 }
|
||||
}
|
||||
});
|
||||
|
||||
let metadata = attach_client_request_body_metadata(
|
||||
Some(json!({ "trace_id": "trace-1" })),
|
||||
Some(&client_body),
|
||||
)
|
||||
.expect("metadata should remain");
|
||||
assert_eq!(metadata["requested_reasoning_effort"], "high");
|
||||
|
||||
let metadata = attach_provider_request_body_metadata(
|
||||
Some(metadata),
|
||||
Some("gemini:generate_content"),
|
||||
Some("gemini-3.8-flash"),
|
||||
Some("gemini-3.8-flash"),
|
||||
Some(&provider_body),
|
||||
)
|
||||
.expect("metadata should remain");
|
||||
|
||||
assert_eq!(metadata["requested_reasoning_effort"], "high");
|
||||
assert_eq!(metadata["provider_reasoning_effort"], "xhigh");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn provider_request_body_metadata_uses_final_provider_body_as_source_of_truth() {
|
||||
let metadata = Some(json!({
|
||||
|
||||
Reference in New Issue
Block a user