search: an AI Studio key that searches by googleSearch searches for other providers' models
cocoasoda on Discord: a Gemini AI Studio key provider searches natively
(googleSearch grounding, geminiKeySearches), but it never showed in the
search-for-other-providers (代搜索) list. searchRank knew only a Google
sign-in (googleAccount) at rank 5, so namedSearcherRank gave such a key
-1 and Searchers() left it out; autoSearcher never chose it.
searchRank now gives geminiKeySearches(p) rank 5 too: a saved key
provider, not a plugin, not Vertex, whose Gemini searches itself. That is
the same rank and the same googleSearch route as a Google sign-in, and
Searchers() marks it Own (it searches by its own tool, not a relay or a
search key).
Run on mote (macOS 27), at the rebased head e76db5515's tree:
- go test -count=1 ./internal/gateway -run
'AIStudio|GeminiKey|Searcher|WebSearch': ok; ./internal/gui -run
'Budget|Script|Search': ok; gofmt -l: clean.
- GUI: searcher-pick, searcher-then, search-instead, search-order,
provider-search (chromium + webkit): 84/84.
- Before the rebase, at eb779ce92 + this: GOOS=linux and GOOS=windows
go vet -tags nogui ./internal/gateway ./internal/gui: ok.
- TestAIStudioKeySearchesForOthers: a fake AI Studio endpoint
(httptest, no network) answers the googleSearch call; the test checks
rank 5, Own, the small model gemini-2.5-flash, autoSearcher's pick,
and that another provider's model's web search goes there once, with
tools [{"googleSearch":{}}] and x-goog-api-key.
Broken by hand: the new case taken out of searchRank, the test is red
("rank -1, by hand only false").
Not tried: a real AI Studio key; the whole ./internal/gateway and
./internal/gui packages at this head (a run at the old base is still
going).
This commit is contained in:
@@ -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`.
|
||||
|
||||
|
||||
@@ -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])
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user