fix(translator/antigravity): support max_completion_tokens in openai chat completions - #192
Open
warelik wants to merge 2 commits into
Open
fix(translator/antigravity): support max_completion_tokens in openai chat completions#192warelik wants to merge 2 commits into
warelik wants to merge 2 commits into
Conversation
…chat completions OpenAI reasoning models send max_completion_tokens instead of max_tokens. Map max_completion_tokens to request.generationConfig.maxOutputTokens when max_tokens is absent, preserving priority. Refs: router-for-me/CLIProxyAPI#5108
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OpenAI deprecated
max_tokensin favor ofmax_completion_tokensfor reasoning models (o1,o3-mini, newergpt-4oversions), and modern OpenAI client libraries sendmax_completion_tokensby default.When translating OpenAI Chat Completions requests to Antigravity (
ConvertOpenAIRequestToAntigravity), onlymax_tokenswas inspected. When a client suppliedmax_completion_tokenswithoutmax_tokens,request.generationConfig.maxOutputTokenswas omitted from the upstream Antigravity payload, causing upstream models to ignore client token limits.Fix
internal/translator/antigravity/openai/chat-completions/antigravity_openai_request.go:72: UpdatedConvertOpenAIRequestToAntigravityto readmax_tokensfirst, and if absent/non-numeric, fall back tomax_completion_tokens(matching the mapping pattern used ingemini_openai_request.go).Tests
TestConvertOpenAIRequestToAntigravityMapsMaxTokens:only max_tokens: Verifiesmax_tokenssetsmaxOutputTokens.only max_completion_tokens: Verifiesmax_completion_tokenssetsmaxOutputTokens.max_tokens preferred over max_completion_tokens: Verifiesmax_tokensprecedence when both are provided.neither present: VerifiesmaxOutputTokensis omitted.non-numeric max_tokens ignored: Verifies stringmax_tokensis ignored.non-numeric max_completion_tokens ignored: Verifies stringmax_completion_tokensis ignored.Reverse bite-check
Reverting
internal/translator/antigravity/openai/chat-completions/antigravity_openai_request.goto the pre-fix state reproduces the failure wheremax_completion_tokensis ignored:Verification
Output:
Tooling note
The
jbcontextsemantic-search CLI is installed but non-functional in this environment(
jbcontext searchfails withthe OS keychain is not accessible). The equivalentreview passes were performed with the repository's own tooling and manual inspection
instead; this is disclosed for transparency about how the change was reviewed.