A model's web search, when no provider can search, goes to the search APIs the user added; each of them needed a key except a SearXNG of the user's own. You.com answers with no key too, so it is one a user can add in one step. - provider: SearchVendor has KeyOptional (You.com, SearXNG); Ready and check let a vendor that has it go with no key. You.com is listed between Firecrawl and SearXNG, its keys at you.com/platform. - gateway: with no key, GET https://api.you.com/v1/agents/search?query= &count=6 (YouFreeSearch); with a key, POST https://ydc-index.io/v1/search {"query","count"} with X-API-Key, as its API reference says; with a base URL of the user's own and no key, GET <url>/v1/agents/search. Both replies are read from results.web then results.news: the snippets, else the description, and page_age. You.com's errors are a code beside a message, so the message is what the user is told (a 402 "prepaid credit balance has been depleted" is a refused key, the next key or API is asked). Its requests carry the User-Agent tag You.com asked for, "youdotcom-integration/yetone-magpie", after magpie's own. - gui: Settings › Web search lets You.com be added with the key empty, its placeholder saying so (zh, zh-TW, ja, de). - cli: magpie search add you [<key>]; the help lists it. New network addresses: api.you.com (keyless) and ydc-index.io (keyed), asked only when the user adds You.com, with the search query only. Checked against the real service on 10-11: a keyless GET to api.you.com/v1/agents/search answered 200 (testdata/you/free_search.json is that reply, cut to 3 hits), and a real run through askSearchAPIKeys returned 6 pages. ydc-index.io/v1/search answered 402 with no key (testdata/you/keyed_402.json, real bytes) and 403 to a made-up key. The keyless endpoint isn't in the API reference; You.com's own docs pages for third-party tools describe it (free, 100 a day per address, no account), as LiteLLM, ragflow and AnythingLLM use it. you.com/terms bars automated use of its website and apps, not the API. The keyed request shape is from its API reference only: no key with credit was tried. Run: go test -tags nogui . ./internal/gui/ ./internal/provider/ ./internal/backup/ green; ./internal/gateway/ green but TestTurnDoneSaidAtTheTurnsEnd (#1629, fixed in its own commit); search-api.test.cjs in Chromium and WebKit, en/zh, 980/420px green; gui-ja, gui-de and i18n-keys green; gofmt -l; go vet -tags nogui for linux, windows and darwin. The tests make no network request (a stub RoundTripper). Without the change, TestYouSearch, TestYouKeyOutOfCredit, TestYouNeedsNoKey and TestSearchCLIYouWithoutKey fail, and with the GUI's keyOptional check taken out search-api.test.cjs fails in all four Chromium runs (Add sends nothing).
83 lines
3.0 KiB
Go
83 lines
3.0 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// magpie search add, with a key and an address in either order, and rm.
|
|
func TestSearchCLI(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
t.Setenv("USERPROFILE", os.Getenv("HOME"))
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
if err := searchCmd([]string{"add", "tavily"}); err == nil {
|
|
t.Error("tavily added without a key")
|
|
}
|
|
if err := searchCmd([]string{"add", "google", "k"}); err == nil {
|
|
t.Error("an unknown search API added")
|
|
}
|
|
if err := searchCmd([]string{"add", "searxng"}); err == nil {
|
|
t.Error("SearXNG added without its address")
|
|
}
|
|
for _, args := range [][]string{{"add", "Tavily", "tvly-1"}, {"add", "searxng", "url=https://sx.example.com"}, {"add", "brave", "url=https://brave.example.com", "b-1"}} {
|
|
if err := searchCmd(args); err != nil {
|
|
t.Fatalf("%v: %v", args, err)
|
|
}
|
|
}
|
|
// a new address alone keeps the key
|
|
if err := searchCmd([]string{"add", "brave", "url=https://brave2.example.com"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
as := provider.SearchAPIs()
|
|
if len(as) != 3 || as[0] != (provider.SearchAPI{Vendor: "tavily", Key: "tvly-1"}) || as[1].URL != "https://sx.example.com" ||
|
|
as[2] != (provider.SearchAPI{Vendor: "brave", Key: "b-1", URL: "https://brave2.example.com"}) {
|
|
t.Fatalf("%+v", as)
|
|
}
|
|
// a new key alone keeps the base URL the user set (#1580); url= with
|
|
// nothing puts the vendor's own back
|
|
if err := searchCmd([]string{"add", "brave", "b-2"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if as := provider.SearchAPIs(); as[2] != (provider.SearchAPI{Vendor: "brave", Key: "b-2", URL: "https://brave2.example.com"}) {
|
|
t.Fatalf("a new key took the base URL away: %+v", as[2])
|
|
}
|
|
if err := searchCmd([]string{"add", "brave", "url="}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if as := provider.SearchAPIs(); as[2] != (provider.SearchAPI{Vendor: "brave", Key: "b-2"}) || as[2].Base() != "https://api.search.brave.com" {
|
|
t.Fatalf("url= kept the base URL: %+v", as[2])
|
|
}
|
|
for _, bad := range []string{"url=ftp://x.example.com", "url=https://x.example.com/?k=1", "url=https://x.example.com/#a", "url=x.example.com"} {
|
|
if err := searchCmd([]string{"add", "tavily", "tvly-2", bad}); err == nil {
|
|
t.Errorf("%s taken", bad)
|
|
}
|
|
}
|
|
if err := searchCmd(nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := searchCmd([]string{"rm", "tavily"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := searchCmd([]string{"rm", "tavily"}); err == nil {
|
|
t.Error("removed twice")
|
|
}
|
|
if as := provider.SearchAPIs(); len(as) != 2 || as[0].Vendor != "searxng" {
|
|
t.Fatalf("after rm %+v", as)
|
|
}
|
|
}
|
|
|
|
// magpie search add you, with no key, adds You.com's free search (#1626).
|
|
func TestSearchCLIYouWithoutKey(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
t.Setenv("USERPROFILE", os.Getenv("HOME"))
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
if err := searchCmd([]string{"add", "you"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if as := provider.SearchAPIs(); len(as) != 1 || as[0] != (provider.SearchAPI{Vendor: "you"}) {
|
|
t.Fatalf("%+v", as)
|
|
}
|
|
}
|