Repository navigation
feat(websearch): add SpecStream search and page extraction - #11037
Specstreamai wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/tools/web_search_tools.py" line_range="2476-2480" />
<code_context>
+
+ url = kwargs.get("url")
+ try:
+ parsed = urlsplit(url) if isinstance(url, str) else None
+ valid_url = (
+ parsed is not None
+ and parsed.scheme in {"http", "https"}
+ and bool(parsed.hostname)
+ )
+ except ValueError:
</code_context>
<issue_to_address>
**Malformed URLs reach extraction**
When the requested URL contains an invalid port or whitespace, `urlsplit` and the scheme/hostname checks accept URLs with invalid or out-of-range ports, and URLs containing whitespace; the tool sends those URLs to SpecStream, where extraction fails instead of returning the tool's URL-validation error.
Validate the parsed port and reject whitespace before sending the URL, as the DeepSeek extractor does.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and search and extraction tool calls send requests to SpecStream, which the docs identify as paid; any charges or credits consumed before a rollback cannot be restored by reverting. Usage is limited to deployments that select SpecStream and invoke these tools.
Blocking findings: astrbot/core/tools/web_search_tools.py:2480
|
Hi, thanks for putting together a thorough implementation with tests and docs, and for disclosing that you work on SpecStream. As noted in the PR checklist ("If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc."), adding a new built-in web search provider requires prior discussion and confirmation before opening an implementation PR. Each built-in search provider adds ongoing maintenance surface across core tools, agent search logic, WebUI settings, i18n, documentation, and tests. Especially when a proposal comes directly from a commercial service team and includes vendor benchmark claims, the maintainers first need to evaluate product fit, user demand, and long-term maintenance cost—or handle commercial placement inquiries—before reviewing code. Suggested next steps:
Once the maintainers confirm that a built-in integration is wanted, this PR can be revisited. Thanks for understanding! |
|
Thanks for the clear steer. We have written to community@astrbot.app about a built-in provider, and the PR stays as it is until the maintainers say whether they want it. |
SpecStream's search API is the most accurate web search API in the world. It leads WideSearch at 60.9 and SimpleQA Verified at 99, ahead of Parallel, Exa, Tavily and Perplexity: https://specstream.ai/benchmarks
I work on SpecStream.
This adds SpecStream as a web search provider, next to Tavily, Exa, DeepSeek and the others. Title:
feat(websearch): add SpecStream search and page extraction.Modifications / 改动点
The provider follows the DeepSeek provider from #10599: two builtin tools, one key list with rotation and failover, a provider option in the WebUI, i18n, docs, tests.
Endpoints:
GET https://api.specstream.ai/v1/web-search?q=<question>withAuthorization: Bearer <key>. Price: $5 per 1,000 searches. The API has no result-count parameter, so the tool trimssourceslocally tocount(1 to 50, default 10).POST https://api.specstream.ai/v1/extractwith body{"urls": [url], "format": "markdown"}. Price: $0.80 per 1,000 pages. A page with no text is free.Tools (provider value
specstream, key listprovider_settings.websearch_specstream_key):web_search_specstream: maps each entry ofdata.sourcesto a result (title,url,snippet) and returns the same indexed JSON payload as the other providers, so<ref>citations work.specstream_extract_web_page: takes one HTTP or HTTPS URL, returnsURL,Titleand MarkdownContent. A page status other thanok, or an empty text, returns an error that names the status.Files:
astrbot/core/tools/web_search_tools.py: the two tools,_SPECSTREAM_KEY_ROTATOR,_SPECSTREAM_RETRYABLE_HTTP_STATUSES, tool config,WEB_SEARCH_TOOL_NAMES,__all__astrbot/core/astr_main_agent/web_search.py: provider branch and citation tool nameastrbot/core/config/default.py: default key list, provider option, label, subtitle, key fieldastrbot/dashboard/services/chat_service.pyandastrbot/dashboard/services/live_chat_service.py:web_search_specstreamin the supported refs listdashboard/src/i18n/locales/{en-US,zh-CN,ja-JP,ru-RU}/features/config-metadata.json: label, subtitle, key description and hintdocs/en/use/websearch.md,docs/zh/use/websearch.md: provider table row, provider count, extraction notedocs/en/dev/astrbot-config.md,docs/zh/dev/astrbot-config.md: default config, provider value, key fieldtests/unit/test_web_search_tools.py,tests/unit/test_web_search_refs.py,tests/unit/test_astr_main_agent.py,tests/unit/test_func_tool_manager.pyNo new dependencies. No WebUI navigation or layout change; the provider appears in the existing web search provider list.
Screenshots or Test Results / 运行截图或测试结果
All HTTP is mocked. The tests never call the real API and use no real key. They cover the request shape (URL, query params, headers, body), source mapping and local trimming, citation payload, invalid parameters, missing key, key rotation on 402, a raise on 503, a raise after every key fails with 401, extract success, extract page statuses
blockedandempty, and invalid URLs.Run on Linux with Python 3.12 after
uv sync --group dev:ruff formatandruff checkontests/unit/test_web_search_tools.pyandtests/unit/test_func_tool_manager.pystill report lines that are onmastertoday (the AnySearch fake classes and oneQ000single quote at line 1909 oftest_web_search_tools.py). I left those lines unchanged. Every line this PR adds in those two files is formatted.Docs:
docs:buildfinished withbuild complete in 128.13s.pnpmis not installed on the machine I used, so I ran the same script withbun run docs:buildindocs/. The four locale JSON files parse as valid JSON.I did not run the dashboard in a browser.
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。 Not done before this PR. This PR is the proposal.
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
📚 I checked the affected WebUI instructions and screenshots in
docs/zhanddocs/enagainst the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog./ 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新
docs/zh和docs/en的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。 No entry point is renamed or moved. The provider table and config reference are updated in both languages.🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Add SpecStream search and page extraction as a configurable web search provider.
New Features:
Enhancements:
Documentation:
Tests: