gateway: Gemini 4 Hydrogen keeps xhigh on Gemini's own API

withGeminiEffort capped every Gemini at high, since no Gemini before took
more. Gemini 4 Hydrogen takes XHIGH (Google's model page: LOW, MEDIUM,
HIGH, XHIGH), so an agent asking xhigh or max on the native Gemini path
got high. A level above high now goes to the nearest the catalog lists
for the model (catalog.EffortsOf), and stays high for a model that lists
none above it or isn't in the catalog. The translated Vertex path already
fitted the level from the same metadata.

Run (mote): go test -tags nogui ./internal/gateway -run
'GeminiEffort|VertexEffort|Vertex' and the vet runs of the commit before.
Broken by hand: decide.go reverted, TestWithGeminiEffortAboveHigh red
(hydrogen at xhigh and max: high, want xhigh).
Not tried: a real Hydrogen request.

Rerun after rebasing onto origin/main 96558cfde: go test of provider,
gateway and catalog -run Vertex|GeminiEffort|Preset|Effort, ok on mote.
This commit is contained in:
yetone
2026-11-13 15:06:26 +08:00
parent 51c3ecc573
commit 15500d4378
2 changed files with 43 additions and 2 deletions
+31
View File
@@ -4,6 +4,8 @@ import (
"io"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"sync"
"testing"
@@ -120,6 +122,35 @@ func TestAgyAgentEffort(t *testing.T) {
}
}
// A Gemini that lists a level above high (Gemini 4 Hydrogen's xhigh, as
// Google's model page and models.dev give it) is sent it, and max goes as
// its nearest, xhigh; a Gemini listing high at most (Carbon), or none, is
// still sent high (#6452).
func TestWithGeminiEffortAboveHigh(t *testing.T) {
t.Setenv("XDG_CACHE_HOME", t.TempDir())
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
if err := os.WriteFile(catalog.CachePath(), []byte(`{"google-vertex":{"models":{
"gemini-4-hydrogen":{"id":"gemini-4-hydrogen","reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high","xhigh"]}]},
"gemini-4-carbon":{"id":"gemini-4-carbon","reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high"]}]}}}}`), 0o644); err != nil {
t.Fatal(err)
}
catalog.Reset()
t.Cleanup(catalog.Reset)
for _, c := range []struct{ model, effort, want string }{
{"gemini-4-hydrogen", "xhigh", "xhigh"},
{"gemini-4-hydrogen", "max", "xhigh"},
{"gemini-4-hydrogen", "high", "high"},
{"gemini-4-carbon", "xhigh", "high"},
{"gemini-4-carbon", "max", "high"},
{"gemini-3.9-unlisted", "max", "high"},
} {
out := withGeminiEffort([]byte(`{"contents":[]}`), c.model, c.effort)
if got := gjson.GetBytes(out, "generationConfig.thinkingConfig.thinkingLevel").String(); got != c.want {
t.Errorf("%s at %s: %s, want %s", c.model, c.effort, got, c.want)
}
}
}
// withGeminiEffort writes a Gemini request's thinkingConfig as the model
// takes it, and a Gemini before 2.5, which doesn't think, is left alone.
func TestWithGeminiEffort(t *testing.T) {
+12 -2
View File
@@ -25,6 +25,7 @@ import (
"sync"
"time"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/usage"
)
@@ -931,7 +932,8 @@ func withModelEffort(proto provider.Protocol, body []byte, model, effort string)
// for effort, as model takes it, keeping includeThoughts as asked: a
// Gemini 2.5 a budget in its range (vertexBudgets; it turns a level away),
// a Gemini 3 a level of low..high (none takes xhigh or max, and it can't
// stop thinking, so none is low), a Gemini before 2.5 nothing, as it
// stop thinking, so none is low; above high only where the catalog lists
// it, Gemini 4 Hydrogen's xhigh), a Gemini before 2.5 nothing, as it
// doesn't think. Another model (agy asking an OpenAI one on Gemini's API)
// is asked the level itself, which the translation reads, and none as a
// budget of 0. Antigravity CLI's own request sends thinkingBudget -1, or
@@ -998,7 +1000,15 @@ func withGeminiEffort(body []byte, model, effort string) []byte {
level = "low"
}
case at > slices.Index(effortRank, "high"):
level = "high"
// above high only where the model lists such a level: Gemini
// 4 Hydrogen takes xhigh, every Gemini before it high at most
fit := "high"
if ls := catalog.EffortsOf(m); len(ls) > 0 {
if l := catalog.NearestEffort(level, ls); slices.Index(effortRank, l) > slices.Index(effortRank, "high") {
fit = l
}
}
level = fit
}
tc["thinkingLevel"] = level
case level == "none":