Skip to content

Commit 5b01eba

Browse files
authored
Merge branch 'router-for-me:main' into main
2 parents 8203bf6 + cb580cd commit 5b01eba

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

internal/registry/model_definitions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ func GetGeminiModels() []*ModelInfo {
222222
InputTokenLimit: 1048576,
223223
OutputTokenLimit: 65536,
224224
SupportedGenerationMethods: []string{"generateContent", "countTokens", "createCachedContent", "batchGenerateContent"},
225+
Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true},
225226
},
226227
}
227228
}
@@ -301,6 +302,7 @@ func GetGeminiVertexModels() []*ModelInfo {
301302
InputTokenLimit: 1048576,
302303
OutputTokenLimit: 65536,
303304
SupportedGenerationMethods: []string{"generateContent", "countTokens", "createCachedContent", "batchGenerateContent"},
305+
Thinking: &ThinkingSupport{Min: 128, Max: 32768, ZeroAllowed: false, DynamicAllowed: true},
304306
},
305307
}
306308
}

internal/runtime/executor/antigravity_executor.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/google/uuid"
1818
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
1919
"github.com/router-for-me/CLIProxyAPI/v6/internal/registry"
20+
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
2021
cliproxyauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
2122
cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/executor"
2223
sdktranslator "github.com/router-for-me/CLIProxyAPI/v6/sdk/translator"
@@ -58,6 +59,20 @@ func (e *AntigravityExecutor) Identifier() string { return antigravityAuthType }
5859
// PrepareRequest implements ProviderExecutor.
5960
func (e *AntigravityExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error { return nil }
6061

62+
// applyThinkingMetadata applies thinking config from model suffix metadata (e.g., -reasoning, -thinking-N).
63+
// It trusts user intent when suffix is used, even if registry doesn't have Thinking metadata.
64+
func applyThinkingMetadata(translated []byte, metadata map[string]any, model string) []byte {
65+
budgetOverride, includeOverride, ok := util.GeminiThinkingFromMetadata(metadata)
66+
if !ok {
67+
return translated
68+
}
69+
if budgetOverride != nil && util.ModelSupportsThinking(model) {
70+
norm := util.NormalizeThinkingBudget(model, *budgetOverride)
71+
budgetOverride = &norm
72+
}
73+
return util.ApplyGeminiCLIThinkingConfig(translated, budgetOverride, includeOverride)
74+
}
75+
6176
// Execute handles non-streaming requests via the antigravity generate endpoint.
6277
func (e *AntigravityExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (resp cliproxyexecutor.Response, err error) {
6378
token, updatedAuth, errToken := e.ensureAccessToken(ctx, auth)
@@ -75,6 +90,8 @@ func (e *AntigravityExecutor) Execute(ctx context.Context, auth *cliproxyauth.Au
7590
to := sdktranslator.FromString("antigravity")
7691
translated := sdktranslator.TranslateRequest(from, to, req.Model, bytes.Clone(req.Payload), false)
7792

93+
translated = applyThinkingMetadata(translated, req.Metadata, req.Model)
94+
7895
baseURLs := antigravityBaseURLFallbackOrder(auth)
7996
httpClient := newProxyAwareHTTPClient(ctx, e.cfg, auth, 0)
8097

@@ -166,6 +183,8 @@ func (e *AntigravityExecutor) ExecuteStream(ctx context.Context, auth *cliproxya
166183
to := sdktranslator.FromString("antigravity")
167184
translated := sdktranslator.TranslateRequest(from, to, req.Model, bytes.Clone(req.Payload), true)
168185

186+
translated = applyThinkingMetadata(translated, req.Metadata, req.Model)
187+
169188
baseURLs := antigravityBaseURLFallbackOrder(auth)
170189
httpClient := newProxyAwareHTTPClient(ctx, e.cfg, auth, 0)
171190

internal/util/gemini_thinking.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ func ParseGeminiThinkingSuffix(model string) (string, *int, *bool, bool) {
3434
return base, &budgetValue, &include, true
3535
}
3636

37+
// Handle "-reasoning" suffix: enables thinking with dynamic budget (-1)
38+
// Maps: gemini-2.5-flash-reasoning -> gemini-2.5-flash with thinkingBudget=-1
39+
if strings.HasSuffix(lower, "-reasoning") {
40+
base := model[:len(model)-len("-reasoning")]
41+
budgetValue := -1 // Dynamic budget
42+
include := true
43+
return base, &budgetValue, &include, true
44+
}
45+
3746
idx := strings.LastIndex(lower, "-thinking-")
3847
if idx == -1 {
3948
return model, nil, nil, false

0 commit comments

Comments
 (0)