feat(util): add -reasoning suffix support for Gemini models
Unified · Split
| @@ -17,6 +17,7 @@ import ( · 16 unmodified lines | |||
| 17 | "github.com/google/uuid" | 17 | "github.com/google/uuid" |
| 18 | "github.com/router-for-me/CLIProxyAPI/v6/internal/config" | 18 | "github.com/router-for-me/CLIProxyAPI/v6/internal/config" |
| 19 | "github.com/router-for-me/CLIProxyAPI/v6/internal/registry" | 19 | "github.com/router-for-me/CLIProxyAPI/v6/internal/registry" |
| 20 | "github.com/router-for-me/CLIProxyAPI/v6/internal/util" | ||
| 20 | cliproxyauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth" | 21 | cliproxyauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth" |
| 21 | cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/executor" | 22 | cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/executor" |
| 22 | sdktranslator "github.com/router-for-me/CLIProxyAPI/v6/sdk/translator" | 23 | sdktranslator "github.com/router-for-me/CLIProxyAPI/v6/sdk/translator" |
| @@ -58,6 +59,20 @@ func (e *AntigravityExecutor) Identifier() string { return antigravityAuthType } · 35 unmodified lines | |||
| 58 | // PrepareRequest implements ProviderExecutor. | 59 | // PrepareRequest implements ProviderExecutor. |
| 59 | func (e *AntigravityExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error { return nil } | 60 | func (e *AntigravityExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error { return nil } |
| 60 | 61 | ||
| 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 | |||
| 61 | // Execute handles non-streaming requests via the antigravity generate endpoint. | 76 | // Execute handles non-streaming requests via the antigravity generate endpoint. |
| 62 | func (e *AntigravityExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (resp cliproxyexecutor.Response, err error) { | 77 | func (e *AntigravityExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (resp cliproxyexecutor.Response, err error) { |
| 63 | token, updatedAuth, errToken := e.ensureAccessToken(ctx, auth) | 78 | token, updatedAuth, errToken := e.ensureAccessToken(ctx, auth) |
| @@ -75,6 +90,8 @@ func (e *AntigravityExecutor) Execute(ctx context.Context, auth *cliproxyauth.Au · 11 unmodified lines | |||
| 75 | to := sdktranslator.FromString("antigravity") | 90 | to := sdktranslator.FromString("antigravity") |
| 76 | translated := sdktranslator.TranslateRequest(from, to, req.Model, bytes.Clone(req.Payload), false) | 91 | translated := sdktranslator.TranslateRequest(from, to, req.Model, bytes.Clone(req.Payload), false) |
| 77 | 92 | ||
| 93 | translated = applyThinkingMetadata(translated, req.Metadata, req.Model) | ||
| 94 | |||
| 78 | baseURLs := antigravityBaseURLFallbackOrder(auth) | 95 | baseURLs := antigravityBaseURLFallbackOrder(auth) |
| 79 | httpClient := newProxyAwareHTTPClient(ctx, e.cfg, auth, 0) | 96 | httpClient := newProxyAwareHTTPClient(ctx, e.cfg, auth, 0) |
| 80 | 97 | ||
| @@ -166,6 +183,8 @@ func (e *AntigravityExecutor) ExecuteStream(ctx context.Context, auth *cliproxya · 85 unmodified lines | |||
| 166 | to := sdktranslator.FromString("antigravity") | 183 | to := sdktranslator.FromString("antigravity") |
| 167 | translated := sdktranslator.TranslateRequest(from, to, req.Model, bytes.Clone(req.Payload), true) | 184 | translated := sdktranslator.TranslateRequest(from, to, req.Model, bytes.Clone(req.Payload), true) |
| 168 | 185 | ||
| 186 | translated = applyThinkingMetadata(translated, req.Metadata, req.Model) | ||
| 187 | |||
| 169 | baseURLs := antigravityBaseURLFallbackOrder(auth) | 188 | baseURLs := antigravityBaseURLFallbackOrder(auth) |
| 170 | httpClient := newProxyAwareHTTPClient(ctx, e.cfg, auth, 0) | 189 | httpClient := newProxyAwareHTTPClient(ctx, e.cfg, auth, 0) |
| 171 | 190 | ||
| @@ -34,6 +34,15 @@ func ParseGeminiThinkingSuffix(model string) (string, *int, *bool, bool) { · 33 unmodified lines | |||
| 34 | return base, &budgetValue, &include, true | 34 | return base, &budgetValue, &include, true |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 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 | |||
| 37 | idx := strings.LastIndex(lower, "-thinking-") | 46 | idx := strings.LastIndex(lower, "-thinking-") |
| 38 | if idx == -1 { | 47 | if idx == -1 { |
| 39 | return model, nil, nil, false | 48 | return model, nil, nil, false |