diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md index 138199e13..a341210c7 100644 --- a/docs/subsystems/gateway-routing.md +++ b/docs/subsystems/gateway-routing.md @@ -1035,6 +1035,11 @@ only the hand-typed ones. Before, it was left out of the picker while the page listed it among the relays to pick by hand (axelburks on Discord). Covered by `TestSearcherRelayWithoutModelList` and `TestSearcherPickerOffersResponsesRelay`. +A key at AI Studio's Gemini API (`geminiKeySearches`) ranks with a Google +sign-in (5), by googleSearch, and like one is `Own`: its own models search +first whoever is named. Before, it searched for its own models only and +the picker never listed it (cocoasoda on Discord, +`TestAIStudioKeySearchesForOthers`). Covered by `TestCommandCodeSearchesForOtherModels`, `TestPluginSearchModelIsASearcher` and `TestSearcherChosen`. diff --git a/internal/gateway/gemini_aistudio_search_test.go b/internal/gateway/gemini_aistudio_search_test.go index e72ca10d0..5dc127af9 100644 --- a/internal/gateway/gemini_aistudio_search_test.go +++ b/internal/gateway/gemini_aistudio_search_test.go @@ -212,3 +212,48 @@ func TestGeminiKeySearchesScope(t *testing.T) { t.Error("a Google sign-in is taken for an AI Studio key") } } + +// An AI Studio key that searches by googleSearch is a searcher like a +// Google sign-in (cocoasoda on Discord: 代搜索供应商 had no Gemini): Settings +// lists it, its own models first (Own), and magpie picks it by itself to +// search for another provider's model, which can't, on the user's key. +func TestAIStudioKeySearchesForOthers(t *testing.T) { + s, calls := aiStudio(t, nil) + other := provider.Provider{ID: "plain", Name: "Plain", Chat: "https://plain.example/v1", Key: "k", Models: []string{"plain-1"}} + if err := provider.Save(other); err != nil { + t.Fatal(err) + } + google, err := provider.Find("google") + if err != nil { + t.Fatal(err) + } + if r, manual := namedSearcherRank(*google); r != 5 || manual { + t.Fatalf("rank %d, by hand only %v", r, manual) + } + var found *SearcherChoice + for _, c := range Searchers() { + if c.Provider.ID == "google" { + found = &c + } + if c.Provider.ID == "plain" { + t.Error("a provider that can't search listed") + } + } + if found == nil || !found.Own || found.Small != "gemini-2.5-flash" || found.ManualOnly { + t.Fatalf("Searchers: %+v", found) + } + if p, m, ok := autoSearcher(); !ok || p.ID != "google" || m != "gemini-2.5-flash" { + t.Fatalf("autoSearcher: %q %q %v", p.ID, m, ok) + } + var said string + var hits []Hit + said, hits, err = s.webSearch(searchingOn(t.Context(), other), "who won euro 2024") + if err != nil || !strings.Contains(said, "Spain won Euro 2024") || len(hits) == 0 { + t.Fatalf("search for plain-1: %q %v %v", said, hits, err) + } + gem := geminiCalls(calls()) + if len(gem) != 1 || len(calls()) != 1 { + t.Fatalf("calls %d, Gemini %d", len(calls()), len(gem)) + } + checkGoogleSearch(t, "search for another", gem[0]) +} diff --git a/internal/gateway/search.go b/internal/gateway/search.go index 95d7ae8f4..dcfb47146 100644 --- a/internal/gateway/search.go +++ b/internal/gateway/search.go @@ -339,8 +339,9 @@ func searchRank(p provider.Provider) int { return 4 case partSearcher(p) && slices.ContainsFunc(p.Available(), func(m catalog.Model) bool { return searchesAlone(p, m.ID) }): return 4 - case googleAccount(p): - // Gemini on a Google sign-in, by googleSearch (#757) + case googleAccount(p), geminiKeySearches(p): + // Gemini on a Google sign-in (#757) or an AI Studio key + // (cocoasoda on Discord), by googleSearch return 5 case remoteSearchesAny(p): // another magpie, with the models it searches natively for @@ -473,7 +474,7 @@ func Searchers() []SearcherChoice { if len(ms) == 0 { continue } - out = append(out, SearcherChoice{Provider: p, Small: searcherModel(p), Models: ms, rank: r, ManualOnly: manualOnly, Own: googleAccount(p)}) + out = append(out, SearcherChoice{Provider: p, Small: searcherModel(p), Models: ms, rank: r, ManualOnly: manualOnly, Own: googleAccount(p) || geminiKeySearches(p)}) } slices.SortStableFunc(out, func(a, b SearcherChoice) int { return cmp.Compare(a.rank, b.rank) }) return out @@ -508,8 +509,8 @@ type SearcherChoice struct { // Service is a Kimi Code plan, which searches by its search service, // with no model (and no Small or Models) Service bool - // Own is a Google sign-in, whose Gemini searches for the provider's - // own models first, whoever is named (ownSearcher) + // Own is a Google sign-in or an AI Studio key, whose Gemini searches + // for the provider's own models first, whoever is named (ownSearcher) Own bool } diff --git a/internal/gui/api.go b/internal/gui/api.go index 578f65b78..f1dac93ee 100644 --- a/internal/gui/api.go +++ b/internal/gui/api.go @@ -591,7 +591,8 @@ type searchChoiceJSON struct { // Service is a Kimi Code plan, which searches by its search service: // named by itself, with no model Service bool `json:"service,omitempty"` - // Own is a Google sign-in, which searches for its own models first + // Own is a Google sign-in or an AI Studio key, which searches for its + // own models first Own bool `json:"own,omitempty"` }