新增 Metaso(秘塔搜索)作为 Web 搜索后端#8241
Open
mrluanma wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
_metaso_searchall error paths raise a bareException; consider using a more specific exception type (or a shared custom web-search error) so callers can distinguish Metaso failures from other unexpected errors more reliably. - The type annotation for
Stage.processwas changed fromAsyncGenerator[None, None]toAsyncGenerator[None], which is not the canonical two-parameter form ofAsyncGenerator; it would be clearer and more accurate to keep the full generic parameters or use a higher-levelAsyncIterator/AsyncIterableif the send type is not needed.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_metaso_search` all error paths raise a bare `Exception`; consider using a more specific exception type (or a shared custom web-search error) so callers can distinguish Metaso failures from other unexpected errors more reliably.
- The type annotation for `Stage.process` was changed from `AsyncGenerator[None, None]` to `AsyncGenerator[None]`, which is not the canonical two-parameter form of `AsyncGenerator`; it would be clearer and more accurate to keep the full generic parameters or use a higher-level `AsyncIterator` / `AsyncIterable` if the send type is not needed.
## Individual Comments
### Comment 1
<location path="astrbot/core/pipeline/stage.py" line_range="36" />
<code_context>
self,
event: AstrMessageEvent,
- ) -> None | AsyncGenerator[None, None]:
+ ) -> None | AsyncGenerator[None]:
"""处理事件
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `AsyncGenerator` with a single type argument is invalid for current Python typing and will raise at runtime.
This should remain `AsyncGenerator[None, None]` (or be wrapped in a helper alias) to match the current `AsyncGenerator[T_co, T_contra]` signature in Python ≤3.11. Changing it to a single-argument form assumes future typing changes and will break on currently supported versions with a `TypeError` at import time.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces the Metaso Web Search tool, integrating it into the main agent, configuration defaults, and dashboard localized metadata. The implementation includes the MetasoWebSearchTool class, API interaction logic with support for key rotation, and a suite of unit tests. Additionally, the PR includes minor refactors such as adopting shlex.join for command construction and simplifying AsyncGenerator type hints. Review feedback recommends simplifying conditional checks for HTTP status codes using the in operator.
Add MetasoWebSearchTool as a new web search backend using the Metaso Search API (https://metaso.cn/api/v1/search). Includes a built-in free-tier key (100 queries/day) and supports custom API key rotation via websearch_metaso_key config. - Add Metaso provider config and i18n metadata (en/ru/zh) - Register MetasoWebSearchTool in astr_main_agent - Map Metaso API error codes (401/403/429, code 3003/2005) to descriptive exceptions - Add 17 unit tests covering HTTP errors, API codes, key selection, size clamping, and empty results
4d0f7b5 to
91d68a3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
动机
新增 Metaso(秘塔搜索)作为 Web 搜索后端。Metaso 提供开箱即用的免费 API(每日 100 次查询),用户无需额外配置即可使用网页搜索功能。同时支持通过
websearch_metaso_key配置自定义 API Key 以获取更高配额,并支持多 Key 轮询。改动点
astrbot/core/tools/web_search_tools.py— 新增_metaso_search()异步函数,调用https://metaso.cn/api/v1/search;新增MetasoWebSearchTool工具类,支持 size 参数(范围 1–100);内置免费 API Key_METASO_DEFAULT_API_KEY;新增_METASO_KEY_ROTATOR支持多 Key 轮询;映射 HTTP 401/403/429 和 API 错误码 3003(每日限额)/2005(Key 无效)为描述性异常;在WEB_SEARCH_TOOL_NAMES中注册"web_search_metaso",并更新__all__导出。astrbot/core/astr_main_agent.py— 导入MetasoWebSearchTool并在搜索提供者分发逻辑中注册(provider == "metaso")。astrbot/core/config/default.py— 在提供者下拉列表中新增"metaso"选项;新增websearch_metaso_key默认配置([])及条件 schema 定义。dashboard/src/i18n/locales/{en-US,ru-RU,zh-CN}/features/config-metadata.json— 三语言均新增websearch_metaso_key的 i18n 条目(描述 + 提示语)。tests/unit/test_web_search_tools.py— 新增 16 个单元测试,覆盖:结果映射、默认 Key 回退、自定义 Key 使用、默认载荷、size 边界值(过低/过高)、空结果、HTTP 401/403/429 错误、API 错误码 3003/2005/通用非零码、空 webpages 响应。运行截图或测试结果
全部 26 个测试通过(10 个 Firecrawl + 16 个 Metaso)。
检查清单
Summary by Sourcery
Add Metaso as a new configurable web search backend and integrate it into the agent pipeline and configuration system.
New Features:
Enhancements:
Documentation:
Tests: