mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
**feat(translator): add Antigravity translation logic**
- Introduced request and response translation functions to enable compatibility between OpenAI Chat Completions API and Antigravity. - Registered translation utilities for both streaming and non-streaming scenarios. - Added support for reasoning content, tool calls, and metadata handling. - Established request normalization and embedding for Antigravity-compatible payloads. - Added new fields to `Params` struct for better tracking of finish reasons, usage metadata, and tool usage. - Refactored handling of response transitions, final events, and state-driven logic in `ConvertAntigravityResponseToClaude`. - Introduced `appendFinalEvents` and `resolveStopReason` helper functions for cleaner separation of concerns. - Added `TotalTokenCount` field to `Params` struct for enhanced token tracking. - Updated token count calculations to fallback on `TotalTokenCount` when specific counts are missing. - Introduced `hasNonZeroUsageMetadata` function to validate presence of token data in `usage_metadata`.
This commit is contained in:
@@ -453,6 +453,10 @@ func StripUsageMetadataFromJSON(rawJSON []byte) ([]byte, bool) {
|
||||
usageMetadata = gjson.GetBytes(jsonBytes, "response.usageMetadata")
|
||||
}
|
||||
|
||||
if hasNonZeroUsageMetadata(usageMetadata) {
|
||||
return rawJSON, false
|
||||
}
|
||||
|
||||
if !usageMetadata.Exists() {
|
||||
return rawJSON, false
|
||||
}
|
||||
@@ -475,3 +479,14 @@ func StripUsageMetadataFromJSON(rawJSON []byte) ([]byte, bool) {
|
||||
|
||||
return cleaned, changed
|
||||
}
|
||||
|
||||
// hasNonZeroUsageMetadata checks if any usage token counts are present.
|
||||
func hasNonZeroUsageMetadata(node gjson.Result) bool {
|
||||
if !node.Exists() {
|
||||
return false
|
||||
}
|
||||
return node.Get("totalTokenCount").Int() > 0 ||
|
||||
node.Get("promptTokenCount").Int() > 0 ||
|
||||
node.Get("candidatesTokenCount").Int() > 0 ||
|
||||
node.Get("thoughtsTokenCount").Int() > 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user