search: Doubao Search (Volcengine) as a search API (CyberCaius on Discord)
CyberCaius asked on Discord #help (10-30) for Volcengine's Doubao search under Settings › Models › Search APIs, or a custom API address. Volcengine's Doubao Search Custom (豆包搜索 Custom版, once 联网搜索 / 融合信息搜索, docs.volcengine.com/docs/networked-search/networked-search, the same page as volcengine.com/docs/87772/2272953) can now be added with its API key: - provider.SearchVendors: volcengine, "Doubao Search (Volcengine)", at https://open.feedcoopapi.com, keys at console.volcengine.com/search-infinity/api-key, after DeepSeek. The GUI takes its vendors from SearchVendors, so it shows in the Search API picker with its Get a key link and base URL field; no GUI file changes. - askSearchAPI: POST /search_api/web_search, Bearer key (the default, as the docs and volcengine/mcp-server's askecho_search_infinity send it), body {Query, SearchType: "web", Count: searchHits, Filter: {NeedUrl: true}}. The query is cut to the 100 characters the docs allow. NeedUrl leaves out its 火山如意 cards, which have no URL to cite. - readVolcSearch reads Result.WebResults: Summary as the page's text (the docs recommend it for models; Content is the whole page, Snippet ~200 chars "only for list display"), Snippet when there is no Summary, PublishTime as the page's age, a 1970-01-01 time (its image example's stand-in) as none, and a result with no Url left out. - volcSearchError: its errors are in ResponseMetadata.Error, a code the docs list, and the docs don't say the HTTP status, so the code decides: 10401/10403/10409 rest the key as turned away (403), 10406/10408/ 10410/10412 (free searches spent with none paid, no plan, plan spent) as out of credit (402), 700429 as rate limited (429). Any other code is a plain error, a 200 carrying one included. The key is masked in the error as for every vendor. - A custom address: every search API already takes a base URL (#1580, the field under the key in Settings, url= in the CLI), so an endpoint that answers as Tavily, SearXNG, Brave, Exa, Firecrawl, You.com, DeepSeek or now Doubao Search does can be set there. There is no common format across the vendors (each has its own path, body and reply), so no separate "custom" vendor was added. - Siblings: CLI usage (main.go, search_cli.go's api list and empty-state hint), README.md, README.zh-CN.md, gateway-routing.md's path list and refusal paragraph. The test's reply is the docs' own web-search response example, byte for byte (testdata/volcengine_web_search.json); its error replies are the docs' error example with its "// 该字段为错误码" note taken out (not JSON). Not tried against the real API: no Volcengine search key in this run. Run (worktree on origin/mainc941e0877, then rebased ond31710c71): - TestVolcengineSearchAPI (new): red on the old code (no such vendor). Broken by hand six ways, each red with its own message: Summary not read (Snippet's text), volcSearchError not called (200 10403 read as "no Result in it"), query not cut (150 characters went), NeedUrl dropped (body {"Filter":{}}), 1970 age kept, 10412 not mapped (plain error, not a refusal). Restored: ok. - go test -run Search ./internal/gateway/, go test ./internal/provider/ ./internal/cli/: ok, before and after the rebase. - gofmt -l internal: nothing. go vet -tags nogui ./... on darwin, GOOS=linux, GOOS=windows: ok. - Not run before the push: the full go test ./... . mote had three other sessions' full suites running at load 140-230; it runs after the push and its result goes on the report.
This commit is contained in:
@@ -273,7 +273,7 @@ Find them under Plugins › Discover › Gateway middleware. See [Gateway middle
|
||||
### Also
|
||||
|
||||
- **Library**: write instructions, MCP servers, skills and subagents once; magpie writes them into each agent's files in its format, and removes only what it wrote.
|
||||
- **Web search for any model**: a model that can't search gets magpie's search: a provider that can, or search APIs (Tavily, Brave, Exa, Firecrawl, You.com, DeepSeek, SearXNG), asked in the order you drag them into, each one able to be switched off without losing its key. An API can hold several keys: searches take turns over them (or use them in order with `pick=order`), a key refused lately is asked last, and Tavily keys show what each has used of its limit, in Settings and in `magpie search`. Any agent can mount the same search as an MCP server, with a `web_search` tool and a `web_fetch` tool that reads a page by its URL.
|
||||
- **Web search for any model**: a model that can't search gets magpie's search: a provider that can, or search APIs (Tavily, Brave, Exa, Firecrawl, You.com, DeepSeek, Doubao Search on Volcengine, SearXNG), asked in the order you drag them into, each one able to be switched off without losing its key. An API can hold several keys: searches take turns over them (or use them in order with `pick=order`), a key refused lately is asked last, and Tavily keys show what each has used of its limit, in Settings and in `magpie search`. Any agent can mount the same search as an MCP server, with a `web_search` tool and a `web_fetch` tool that reads a page by its URL.
|
||||
- **Images and video**: an image tool for any agent over MCP, with the model you choose, and videos with a Grok subscription or a MiniMax API key (MiniMax H3).
|
||||
- **Agents kept current**: the Agents page shows each CLI's version, updates it the way it was installed, and gives the commands for the ones you don't have.
|
||||
- **WSL**: on Windows, agents inside WSL distros are wired too, and their sessions counted.
|
||||
|
||||
+1
-1
@@ -273,7 +273,7 @@ magpie plugin options model-map '{"mapping": {"fast": "deepseek/deepseek-chat"}}
|
||||
### 还有
|
||||
|
||||
- **资料库**:指令、MCP 服务器、技能和子代理只写一次,magpie 按每个 Agent 的格式写进它的文件,删除时只删自己写的部分。
|
||||
- **任何模型都能联网搜索**:不能搜索的模型由 magpie 代为搜索,用能搜索的 provider 或搜索 API(Tavily、Brave、Exa、Firecrawl、You.com、DeepSeek、SearXNG),按你拖好的顺序调用,每个都能单独关闭而不删除密钥。一个 API 可以填多个密钥:搜索默认轮流使用(`pick=order` 则按顺序),最近被拒的密钥最后才用;Tavily 的每个密钥用了多少额度,在设置页和 `magpie search` 里都能看到。任何 Agent 都能把同一个搜索挂成 MCP 服务器,提供 `web_search` 工具和按 URL 读取网页的 `web_fetch` 工具。
|
||||
- **任何模型都能联网搜索**:不能搜索的模型由 magpie 代为搜索,用能搜索的 provider 或搜索 API(Tavily、Brave、Exa、Firecrawl、You.com、DeepSeek、火山引擎豆包搜索、SearXNG),按你拖好的顺序调用,每个都能单独关闭而不删除密钥。一个 API 可以填多个密钥:搜索默认轮流使用(`pick=order` 则按顺序),最近被拒的密钥最后才用;Tavily 的每个密钥用了多少额度,在设置页和 `magpie search` 里都能看到。任何 Agent 都能把同一个搜索挂成 MCP 服务器,提供 `web_search` 工具和按 URL 读取网页的 `web_fetch` 工具。
|
||||
- **图片和视频**:通过 MCP 给任何 Agent 一个生图工具,用你选的模型;有 Grok 订阅或 MiniMax API Key(MiniMax H3)还能生成视频。
|
||||
- **Agent 保持最新**:Agents 页显示每个 CLI 的版本,按当初的安装方式更新,没装的也给出安装命令。
|
||||
- **WSL**:在 Windows 上,WSL 发行版里的 Agent 一样能配置,会话也一样统计。
|
||||
|
||||
@@ -753,7 +753,8 @@ answers as that API does (#1580). Empty is the vendor's own
|
||||
(`SearchVendor.Base`); SearXNG has none, so its URL is required. `check`
|
||||
takes only an `http://` or `https://` URL with a host and no `?query` or
|
||||
`#fragment`, since `askSearchAPI` puts the vendor's path after it
|
||||
(`/search`, `/res/v1/web/search`, `/v2/search`, `/v1/tools/search`) with the slash at its end
|
||||
(`/search`, `/res/v1/web/search`, `/v2/search`, `/v1/tools/search`,
|
||||
`/search_api/web_search`) with the slash at its end
|
||||
trimmed. The request goes through the gateway's client, so it follows
|
||||
magpie's proxy settings as the vendor's own address does
|
||||
(`TestSearchFollowsTheSearchersProxy`).
|
||||
@@ -823,7 +824,12 @@ A refused key rests (`searchRestFor`): 401 and 403 ten minutes ("turned
|
||||
away"), 402 an hour ("out of credit"), a rate limit its `Retry-After` held
|
||||
to 30 seconds through 10 minutes (a minute without one). 432 and 433 are
|
||||
Tavily's plan and pay-as-you-go limits, out of credit from Tavily only; from
|
||||
any other vendor they rest as a rate limit. A resting key is not dropped:
|
||||
any other vendor they rest as a rate limit. Doubao Search (Volcengine)
|
||||
says its error in `ResponseMetadata.Error`, possibly with a 200, so
|
||||
`volcSearchError` reads it by its code first: 10401, 10403 and 10409 as
|
||||
403, 10406, 10408, 10410 and 10412 (no free searches left, none paid
|
||||
for, a plan missing or spent) as 402, 700429 as 429; any other code is a
|
||||
plain error (`TestVolcengineSearchAPI`). A resting key is not dropped:
|
||||
it is asked after every key that isn't, the one back soonest first, so a
|
||||
search still has every key to fall back on. A key that answers wakes.
|
||||
Rests are held by vendor and a hash of the key (`searchKeyID`), never the
|
||||
|
||||
@@ -86,7 +86,7 @@ const usage = `magpie — one place to pick every agent's model
|
||||
magpie visible [<agent> <family|provider|group>,… | all | --only-picked | --show-new]
|
||||
which models an agent is shown: families (magpie provider/group set <id> family=…),
|
||||
or only the models ticked for it, a new one off until it is ticked
|
||||
magpie search [add <api> <key>|rm <api>] Tavily, Brave, Exa, Firecrawl, You.com, DeepSeek or SearXNG for web search when no provider can search
|
||||
magpie search [add <api> <key>|rm <api>] Tavily, Brave, Exa, Firecrawl, You.com, DeepSeek, Doubao Search (Volcengine) or SearXNG for web search when no provider can search
|
||||
magpie groups routing groups: several models agents pick as one, group/<id>
|
||||
magpie group add <name> models=<m1>,<m2> [routing=smart|order|rotate|usage|pace|weight|free|fast] [stays=auto|session|turn|off]
|
||||
magpie group <id> | set <id> k=v… | rm <id> show, change or remove one (magpie group help for more)
|
||||
|
||||
@@ -26,7 +26,7 @@ const searchUsage = `usage:
|
||||
magpie search move <api> <n> put one at place n in the order they are asked
|
||||
magpie search rm <api> take one away
|
||||
|
||||
apis: tavily, brave, exa, firecrawl, you, deepseek, searxng
|
||||
apis: tavily, brave, exa, firecrawl, you, deepseek, volcengine, searxng
|
||||
|
||||
url= is the API's base URL, for an endpoint of your own that answers as that API
|
||||
does (e.g. url=https://search.example.com/tavily). Without it the vendor's own is
|
||||
@@ -53,7 +53,7 @@ func searchCmd(args []string) error {
|
||||
if len(args) == 0 {
|
||||
as := provider.StoredSearchAPIs()
|
||||
if len(as) == 0 {
|
||||
fmt.Println(muted.Render(" no search API · magpie search add <tavily|brave|exa|firecrawl|you|deepseek|searxng> <key>"))
|
||||
fmt.Println(muted.Render(" no search API · magpie search add <tavily|brave|exa|firecrawl|you|deepseek|volcengine|searxng> <key>"))
|
||||
return nil
|
||||
}
|
||||
for i, a := range as {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
@@ -229,6 +230,12 @@ func (s *Server) askSearchAPI(ctx context.Context, a provider.SearchAPI, query s
|
||||
// (api-docs.deepseek.com/guides/search); its page text is its
|
||||
// summary, so need_content is left false
|
||||
post("/v1/tools/search", map[string]any{"query": firstRunes(query, deepseekQueryMax), "count": searchHits})
|
||||
case "volcengine":
|
||||
// Doubao Search Custom (volcengine.com/docs/87772/2272953): a
|
||||
// query of 1 to 100 characters, web pages only, and only those
|
||||
// with a URL (NeedUrl leaves out its 火山如意 cards, which have none)
|
||||
post("/search_api/web_search", map[string]any{"Query": firstRunes(query, volcQueryMax), "SearchType": "web",
|
||||
"Count": searchHits, "Filter": map[string]any{"NeedUrl": true}})
|
||||
case "searxng":
|
||||
get("/search", url.Values{"q": {query}, "format": {"json"}})
|
||||
case "you":
|
||||
@@ -290,8 +297,18 @@ func (s *Server) askSearchAPI(ctx context.Context, a provider.SearchAPI, query s
|
||||
if res.StatusCode >= 300 && res.StatusCode < 400 && res.Header.Get("Location") != "" {
|
||||
return nil, fmt.Errorf("%s: it sends the search on to %s, which isn't given its key; set that address instead", res.Status, res.Header.Get("Location"))
|
||||
}
|
||||
if res.StatusCode >= 300 {
|
||||
status := res.StatusCode
|
||||
var volcMsg string
|
||||
if a.Vendor == "volcengine" {
|
||||
// its error is in ResponseMetadata.Error, a code beside the
|
||||
// status, and may come with a 200
|
||||
status, volcMsg = volcSearchError(b, status)
|
||||
}
|
||||
if status >= 300 {
|
||||
msg := provider.APIError(b, res.Status)
|
||||
if volcMsg != "" {
|
||||
msg = volcMsg
|
||||
}
|
||||
if a.Vendor == "you" {
|
||||
// You.com's error is a code ("payment_required"), its message
|
||||
// beside it the words
|
||||
@@ -305,8 +322,8 @@ func (s *Server) askSearchAPI(ctx context.Context, a provider.SearchAPI, query s
|
||||
if a.Key != "" {
|
||||
msg = strings.ReplaceAll(msg, a.Key, provider.MaskSearchKey(a.Key))
|
||||
}
|
||||
if keyRefusal(res.StatusCode) {
|
||||
return nil, searchRefused{res.StatusCode, msg, res.Header.Get("Retry-After")}
|
||||
if keyRefusal(status) {
|
||||
return nil, searchRefused{status, msg, res.Header.Get("Retry-After")}
|
||||
}
|
||||
return nil, errors.New(msg)
|
||||
}
|
||||
@@ -322,8 +339,11 @@ func (s *Server) askSearchAPI(ctx context.Context, a provider.SearchAPI, query s
|
||||
|
||||
// readSearchAPI reads the pages out of a search API's reply.
|
||||
func readSearchAPI(vendor string, b []byte) ([]foundPage, error) {
|
||||
if vendor == "you" {
|
||||
switch vendor {
|
||||
case "you":
|
||||
return readYouSearch(b)
|
||||
case "volcengine":
|
||||
return readVolcSearch(b)
|
||||
}
|
||||
type result struct {
|
||||
Title string `json:"title"`
|
||||
@@ -384,6 +404,91 @@ func readSearchAPI(vendor string, b []byte) ([]foundPage, error) {
|
||||
// query; a longer one is turned away with 400.
|
||||
const deepseekQueryMax = 128
|
||||
|
||||
// volcQueryMax is the most characters Doubao Search takes in a query.
|
||||
const volcQueryMax = 100
|
||||
|
||||
// volcSearchError is the status a Doubao Search reply stands for, and its
|
||||
// error's words: its ResponseMetadata.Error, read by its code, as a key
|
||||
// turned away (403), out of credit (402) or rate limited (429), or as
|
||||
// the status it came with; a reply with no error is its own status.
|
||||
func volcSearchError(b []byte, status int) (int, string) {
|
||||
var out struct {
|
||||
ResponseMetadata struct {
|
||||
Error *struct {
|
||||
CodeN int
|
||||
Code string
|
||||
Message string
|
||||
}
|
||||
}
|
||||
}
|
||||
if json.Unmarshal(b, &out) != nil || out.ResponseMetadata.Error == nil {
|
||||
return status, ""
|
||||
}
|
||||
e := out.ResponseMetadata.Error
|
||||
code := e.CodeN
|
||||
if code == 0 {
|
||||
code, _ = strconv.Atoi(e.Code)
|
||||
}
|
||||
msg := strings.TrimSpace(fmt.Sprintf("%d %s", code, e.Message))
|
||||
switch code {
|
||||
case 10401, 10403, 10409:
|
||||
// a key it doesn't know, a service not opened for it, a plan's
|
||||
// key that can't search the web this way
|
||||
return 403, msg
|
||||
case 10406, 10408, 10410, 10412:
|
||||
// the free searches spent and none paid for, no plan, a plan
|
||||
// spent
|
||||
return 402, msg
|
||||
case 700429:
|
||||
return 429, msg
|
||||
}
|
||||
if status < 300 {
|
||||
status = 502
|
||||
}
|
||||
return status, msg
|
||||
}
|
||||
|
||||
// readVolcSearch reads Doubao Search's reply: its pages under
|
||||
// Result.WebResults, each with a Summary (what its docs give a model:
|
||||
// the page's text about the query) and a short Snippet.
|
||||
func readVolcSearch(b []byte) ([]foundPage, error) {
|
||||
type hit struct {
|
||||
Title, Url, Summary, Snippet, PublishTime string
|
||||
}
|
||||
var out struct {
|
||||
Result *struct {
|
||||
WebResults []hit
|
||||
}
|
||||
}
|
||||
if err := json.Unmarshal(b, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Result == nil {
|
||||
return nil, errors.New("no Result in it")
|
||||
}
|
||||
var pages []foundPage
|
||||
for _, h := range out.Result.WebResults {
|
||||
if h.Url == "" {
|
||||
continue
|
||||
}
|
||||
text := h.Summary
|
||||
if strings.TrimSpace(text) == "" {
|
||||
text = h.Snippet
|
||||
}
|
||||
title := searchPlain(h.Title)
|
||||
if title == "" {
|
||||
title = h.Url
|
||||
}
|
||||
age := h.PublishTime
|
||||
if strings.HasPrefix(age, "1970-01-01") {
|
||||
// its time for a page it has none for
|
||||
age = ""
|
||||
}
|
||||
pages = append(pages, foundPage{Title: title, URL: h.Url, Text: clipText(searchPlain(text), pageText), Age: age})
|
||||
}
|
||||
return pages, nil
|
||||
}
|
||||
|
||||
// firstRunes is s cut to at most n characters, with nothing added.
|
||||
func firstRunes(s string, n int) string {
|
||||
i := 0
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -334,3 +335,133 @@ func TestDeepSeekSearchAPI(t *testing.T) {
|
||||
t.Errorf("vendor %+v", v)
|
||||
}
|
||||
}
|
||||
|
||||
// TestVolcengineSearchAPI: Doubao Search Custom (Volcengine) answers
|
||||
// from its docs' own example reply (volcengine.com/docs/87772/2272953),
|
||||
// asked as its docs say, its errors read by their code (CyberCaius on
|
||||
// Discord).
|
||||
func TestVolcengineSearchAPI(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
reply, err := os.ReadFile("testdata/volcengine_web_search.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// its docs' error example, its "// 该字段为错误码" note taken out
|
||||
errReply := func(code int, msg string) string {
|
||||
return `{
|
||||
"ResponseMetadata": {
|
||||
"RequestId": "202505231206578F7BD0BCD73AF8703C1E",
|
||||
"Action": "WebSearch",
|
||||
"Version": "2025-01-01",
|
||||
"Service": "volc_torchlight_api",
|
||||
"Region": "cn-beijing",
|
||||
"Error": {
|
||||
"CodeN": ` + strconv.Itoa(code) + `,
|
||||
"Code": "` + strconv.Itoa(code) + `",
|
||||
"Message": "` + msg + `"
|
||||
}
|
||||
},
|
||||
"Result": null
|
||||
}`
|
||||
}
|
||||
var mu sync.Mutex
|
||||
var got []map[string]any
|
||||
var paths, auths []string
|
||||
answer := func(w http.ResponseWriter) { w.Write(reply) }
|
||||
f := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
var body map[string]any
|
||||
json.Unmarshal(b, &body)
|
||||
mu.Lock()
|
||||
got = append(got, body)
|
||||
paths = append(paths, r.Method+" "+r.URL.Path+" "+r.Header.Get("Content-Type"))
|
||||
auths = append(auths, r.Header.Get("Authorization"))
|
||||
a := answer
|
||||
mu.Unlock()
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
a(w)
|
||||
}))
|
||||
t.Cleanup(f.Close)
|
||||
s := New()
|
||||
a := provider.SearchAPI{Vendor: "volcengine", Key: "volc-key-123456", URL: f.URL}
|
||||
long := strings.Repeat("搜", 150)
|
||||
for _, q := range []string{"北京最新游玩攻略", long} {
|
||||
pages, err := s.askSearchAPI(context.Background(), a, q)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(pages) != 2 || pages[0].URL != "https://c.m.163.com/news/a/L4U501RM0556LJ9Q.html" ||
|
||||
pages[0].Title != "2026北京5日游超全攻略|行前预约、交通住宿、经典路线、避坑指南一站式拆解" ||
|
||||
!strings.HasPrefix(pages[0].Text, "2026北京5日游超全攻略|行前预约、交通住宿、经典路线、避坑指南一站式拆解 北京旅游——行前准备") ||
|
||||
!strings.Contains(pages[0].Text, "高铁(首选)") || // its Summary, not its Snippet
|
||||
strings.Contains(pages[0].Text, "旅游定制小团 2026-08-22") || // nor its Content
|
||||
pages[0].Age != "2026-08-22T09:16:00+08:00" ||
|
||||
pages[1].URL != "https://www.cnblogs.com/chun-wan-lv/p/22651954" || pages[1].Age != "2026-08-24T11:37:00+08:00" {
|
||||
t.Fatalf("pages %+v", pages)
|
||||
}
|
||||
if len(pages[0].Text) > pageText+len("…") {
|
||||
t.Fatalf("text of %d bytes", len(pages[0].Text))
|
||||
}
|
||||
}
|
||||
if paths[0] != "POST /search_api/web_search application/json" || auths[0] != "Bearer volc-key-123456" {
|
||||
t.Fatalf("asked %q with %q", paths[0], auths[0])
|
||||
}
|
||||
b, _ := json.Marshal(got[0])
|
||||
if string(b) != `{"Count":6,"Filter":{"NeedUrl":true},"Query":"北京最新游玩攻略","SearchType":"web"}` {
|
||||
t.Fatalf("body %s", b)
|
||||
}
|
||||
if q, _ := got[1]["Query"].(string); q != strings.Repeat("搜", volcQueryMax) {
|
||||
t.Fatalf("a long query went as %d characters", len([]rune(q)))
|
||||
}
|
||||
|
||||
// a page with no URL is left out, and a 1970 time is none
|
||||
mu.Lock()
|
||||
answer = func(w http.ResponseWriter) {
|
||||
io.WriteString(w, `{"ResponseMetadata":{"RequestId":"r"},"Result":{"ResultCount":2,"WebResults":[`+
|
||||
`{"Id":"a","SortId":1,"Title":"天气","SiteName":"火山如意","Url":"","Snippet":"晴"},`+
|
||||
`{"Id":"b","SortId":2,"Title":"<em>Go</em> 下载","Url":"https://go.dev/dl/","Snippet":"Download Go.","Summary":"","PublishTime":"1970-01-01T08:00:00+08:00"}]}}`)
|
||||
}
|
||||
mu.Unlock()
|
||||
pages, err := s.askSearchAPI(context.Background(), a, "go")
|
||||
if err != nil || len(pages) != 1 || pages[0].Title != "Go 下载" || pages[0].Text != "Download Go." || pages[0].Age != "" {
|
||||
t.Fatalf("pages %+v, %v", pages, err)
|
||||
}
|
||||
|
||||
// an error comes in ResponseMetadata.Error, with a 200 or a status
|
||||
for _, c := range []struct {
|
||||
status, code, want int
|
||||
why string
|
||||
}{
|
||||
{200, 10403, 403, "turned away"},
|
||||
{401, 10401, 403, "turned away"},
|
||||
{200, 10406, 402, "out of credit"},
|
||||
{200, 10412, 402, "out of credit"},
|
||||
{429, 700429, 429, "rate limited"},
|
||||
{200, 700429, 429, "rate limited"},
|
||||
{200, 10400, 0, ""},
|
||||
{500, 10500, 0, ""},
|
||||
} {
|
||||
mu.Lock()
|
||||
answer = func(w http.ResponseWriter) {
|
||||
w.WriteHeader(c.status)
|
||||
io.WriteString(w, errReply(c.code, "volc-key-123456 query or search type is empty"))
|
||||
}
|
||||
mu.Unlock()
|
||||
_, err := s.askSearchAPI(context.Background(), a, "q")
|
||||
if err == nil || !strings.Contains(err.Error(), strconv.Itoa(c.code)+" ") || strings.Contains(err.Error(), "volc-key-123456") {
|
||||
t.Fatalf("%d %d: %v", c.status, c.code, err)
|
||||
}
|
||||
var r searchRefused
|
||||
if refused := errors.As(err, &r); refused != (c.want != 0) || refused && r.status != c.want {
|
||||
t.Fatalf("%d %d: %#v", c.status, c.code, err)
|
||||
}
|
||||
if c.want != 0 {
|
||||
if _, why := searchRestFor("volcengine", r.status, "", time.Now()); why != c.why {
|
||||
t.Errorf("%d rests as %q", c.code, why)
|
||||
}
|
||||
}
|
||||
}
|
||||
if v, ok := provider.SearchVendorOf("volcengine"); !ok || v.Base != "https://open.feedcoopapi.com" || v.KeyOptional {
|
||||
t.Errorf("vendor %+v", v)
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,7 +1,8 @@
|
||||
package provider
|
||||
|
||||
// Search APIs answer a model's web search when no provider can (#419):
|
||||
// Tavily, Brave Search, Exa, Firecrawl, You.com, a SearXNG of the user's. They are
|
||||
// Tavily, Brave Search, Exa, Firecrawl, You.com, DeepSeek, Volcengine's
|
||||
// Doubao Search, a SearXNG of the user's. They are
|
||||
// kept in providers.json beside the providers, their keys with theirs.
|
||||
|
||||
import (
|
||||
@@ -60,6 +61,9 @@ var SearchVendors = []SearchVendor{
|
||||
{ID: "firecrawl", Name: "Firecrawl", Base: "https://api.firecrawl.dev", KeysURL: "https://www.firecrawl.dev/app/api-keys"},
|
||||
{ID: "you", Name: "You.com", Base: "https://ydc-index.io", KeysURL: "https://you.com/platform", KeyOptional: true},
|
||||
{ID: "deepseek", Name: "DeepSeek", Base: "https://api.deepseek.com", KeysURL: "https://platform.deepseek.com/api_keys"},
|
||||
// Volcengine's Doubao Search Custom (豆包搜索 Custom版, once 联网搜索 /
|
||||
// 融合信息搜索), with an API key from its console (CyberCaius on Discord)
|
||||
{ID: "volcengine", Name: "Doubao Search (Volcengine)", Base: "https://open.feedcoopapi.com", KeysURL: "https://console.volcengine.com/search-infinity/api-key"},
|
||||
{ID: "searxng", Name: "SearXNG", KeyOptional: true},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user