dsh-web-search-gemini:用 Gemini Grounding 替換 DSH 的 web_search 後端

前言

DeepSeek Harness(DSH)裏,模型調用的仍是內置的 web_search 工具,真正決定「搜什麼、返回什麼」的是你在 Cordis 裏選中的搜索提供方(provider)。若把官方 deepseek-official 指到經 CLIProxyAPI 轉發的 Gemini,搜索能跑,但 grounding 結果裏的來源鏈接往往是 vertexaisearch.cloud.google.com/grounding-api-redirect/… 這類跳轉地址;後續 web_fetch 無法按預期跟進,摘要也只取每個鏈接的第一段引用,整體不好用。

alanzhao0128/dsh-web-search-gemini 是社區維護的聯網工具類插件:provider id 爲 cpa-gemini,向 ctx.web 註冊搜索提供方,不新增工具名。選中它之後,模型側仍是 DSH 原生 web_search,後端改爲經 CLIProxyAPI 的 Anthropic 兼容 /v1/messages 調用 Gemini 的 Google 搜索(grounding),並在返回前把符合條件的跳轉鏈接解析爲真實 URL。

這是什麼

  • 包名:@alanzhao/dsh-web-search-gemini(npm 未發佈,需本地構建後以 link: 掛入 profile)
  • 維護者:alanzhao0128
  • 分類:聯網工具(社區目錄 SkillHub 插件頁)
  • 源碼與文檔:GitHub,MIT 許可,當前資料中版本爲 0.1.1

插件只做一件事:在配置 web.searchProvider: cpa-gemini 時,接管 web_search 的後端實現。

與「官方指向 Gemini」的差異

資料裏用表格概括了和「官方 deepseek-official 直接指向 Gemini」的對比,核心如下。

方面 官方 deepseek-official 指向 Gemini 本插件 cpa-gemini
來源鏈接 常爲 grounding 跳轉鏈接,web_fetch 難以跟進 可選將跳轉還原爲真實網址
摘要 每個鏈接只取第一段引用 同一鏈接的多段引用合併、去重,以 … 連接
模型總結 丟棄 可選返回,並帶固定前綴便於覈對

跳轉還原只讀 HTTP 響應頭裏的 location,不訪問目標站點;僅處理 vertexaisearch.cloud.google.com 域名;失敗或超時保留原鏈接,不阻斷搜索。每次搜索會在會話中記錄 web/cpa-gemini-search-request 事件(endpoint、apiVersion、請求體,不含密鑰)。

前提條件

  1. 已有可用的 CLIProxyAPI 實例,賬號池含 Gemini,且能把 Anthropic 格式的 web_search_20250305 轉成 Gemini Google 搜索。自測方式:向 <baseURL>/messages 髮帶該工具的請求,響應中應出現 web_search_tool_result 塊。
  2. DSH 版本與插件 peer 依賴一致,資料寫明爲 0.2.1-rc.5 前後(@deepseek-ai/dsh-web 等 peer 按此聲明)。
  3. Node >= 22(見 package.json engines)。

配置說明

Cordis 補丁行 id 爲 web-search-gemini。字段在每次搜索時重新讀取,改完配置無需重啓 DSH(但若尚未加載插件就指向 cpa-gemini,會出現 WEB_PROVIDER_CONFIGURED_MISSING)。

在 ~/.dsh/profiles/desktop/cordis.patch.yml(或你使用的 profile)中,除插件塊外,還需把 @deepseek-ai/dsh-web 的 searchProvider 設爲 cpa-gemini;抓取仍可用本地 HTTP 提供方,例如:

- id: web
  name: "@deepseek-ai/dsh-web"
  config:
    searchProvider: cpa-gemini
    fetchProvider: http
- id: web-search-gemini
  name: "@alanzhao/dsh-web-search-gemini"
  config:
    baseURL: https://<your-cliproxy-host>/v1
    apiKeyEnv: CLIPROXY_API_KEY

baseURL 爲必填,須含 /v1,請求發往 baseURL + "/messages"。密鑰通過 apiKeyEnv(默認 CLIPROXY_API_KEY)從 DSH credentials(~/.dsh/.credentials.yaml 的 refs)或啓動環境解析;也可用 apiKey 明文,資料不推薦。

其餘默認值與含義(摘自 README):

字段 默認值 說明
model gemini-3.8-flash-high 按 CLIProxyAPI 模型列表填寫
apiVersion 2023-06-01 anthropic-version 頭
maxTokens 4096 生成上限
maxUses 2 單次請求內模型最多搜索次數
resolveRedirects true 是否還原 grounding 跳轉鏈接
resolveTimeoutMs 5000 單鏈接解析超時(毫秒)
includeAnswer true 是否返回模型總結
answerMaxChars 1200 總結字數上限
snippetMaxChars 300 單條摘要字數上限

安裝與啓用

本包未發佈到 npm。資料給出的步驟是克隆倉庫、構建,再用 link: 寫入 profile(以下以 desktop profile 爲例)。安裝前請自行閱讀源碼與 MIT 許可證;插件以當前 DSH 進程權限運行。

git clone https://github.com/alanzhao0128/dsh-web-search-gemini.git
cd dsh-web-search-gemini
npm install && npm run build
  1. 編輯 ~/.dsh/profiles/desktop/package.json:增加依賴並加入 bundles,在該目錄執行 pnpm install。
{
  "dependencies": {
    "@alanzhao/dsh-web-search-gemini": "link:/path/to/dsh-web-search-gemini"
  },
  "dsh": { "profile": { "bundles": ["@alanzhao/dsh-web-search-gemini"] } }
}
  1. 完整退出並重啓 DSH,使插件加載。

  2. 在 cordis.patch.yml 中填寫上文 web 與 web-search-gemini 配置。這一步改完不用重啓;若在第 2 步之前就改好,插件未加載前搜索會報錯。

典型用法

對智能體與 preset 而言,沒有新工具名:在會話裏照常觸發 DSH 的 web_search。區別僅在於結果形態——來源 URL 可被還原、摘要可合併、可選附帶帶前綴的模型總結:

Search summary (model-generated; verify against sources):

模型併發多個查詢時,仍受 DSH agent preset 里約 60 秒的整體時限約束;最慢的一條失敗會導致整次 web_search 失敗,模型往往會自行重試。資料未提供單獨的「一鍵演示命令」,驗證路徑是:配置完成後在 Agent 中發起需要聯網的任務,或在插件目錄執行 smoke(需真實端點):

SMOKE_BASE_URL=https://<your-cliproxy-host>/v1 SMOKE_API_KEY=<key> npm run smoke

適用場景與注意

適合誰:已有 CLIProxyAPI + Gemini、希望繼續用 DSH 原生 web_search / web_fetch 工作流,又需要 grounding 鏈接可抓取、摘要更完整的使用者。

務必注意:

  • 不要打開 DSH「網頁搜索」設置頁的開關。 該頁會把 searchProvider / fetchProvider 改成 DeepSeek 收費 Search / Fetch API,只管理官方提供方。
  • 無自動回退。 選中的提供方不可用時,web_search 直接報錯,不會切換其他提供方。
  • 延遲與模型選擇。 資料稱 gemini-3.8-flash-high 單次搜索約 20–70 秒且波動大;換 gemini-3-flash 約 3–4 秒但總結更淺。整體 60 秒時限只能覆蓋 preset 才能改。
  • 主模型網關。 部分 Anthropic 兼容網關會清空 web_search 工具參數,出現 missing required property "queries",發生在主模型側,與本插件無關。

回滾:僅換回官方搜索時,把 web.searchProvider 改回默認 deepseek-official,無需重啓。完全移除時,刪掉 cordis.patch.yml 中的 web-search-gemini 行,並從 profile 的 dependencies 與 dsh.profile.bundles 去掉本包,pnpm install 後重啓 DSH。

結尾

DSH 生態裏,搜索後端可以插件化替換;社區目錄 SkillHub 與 DeepSeek / 幻方無官方從屬關係。若你的瓶頸是 Gemini grounding 跳轉鏈與摘要格式,而不是「要不要聯網」,可以在自備 CLIProxyAPI 的前提下試用 cpa-gemini。細節與變更以倉庫 README 爲準:https://github.com/alanzhao0128/dsh-web-search-gemini。

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜