Skip to content

Conversation

@Soulter
Copy link
Member

@Soulter Soulter commented Oct 13, 2025


Motivation / 动机

提高 websearch 在中国大陆的可用性

Modifications / 改动点

增加了一个配置项配置 appbuilder api key

修改了 websearch 内置插件

Verification Steps / 验证步骤

Screenshots or Test Results / 运行截图或测试结果

Compatibility & Breaking Changes / 兼容性与破坏性变更

  • 这是一个破坏性变更 (Breaking Change)。/ This is a breaking change.
  • 这不是一个破坏性变更。/ This is NOT a breaking change.

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided
    above
    .
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ 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.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Sourcery 总结

通过添加新的提供商选项、配置密钥以及对百度 AI 搜索 MCP 服务器的插件支持,为在中国的网页搜索启用百度 AI 搜索集成。

新功能:

  • 添加对百度 AI 搜索作为网页搜索提供商的支持,并支持动态 MCP 服务器初始化
  • 引入用于百度 App Builder API 密钥的新配置设置

增强功能:

  • 更新默认配置 schema,以在 websearch_provider 选项中包含 "baidu_ai_search",并在 provider_settings 中包含其 API 密钥字段
Original summary in English

Summary by Sourcery

Enable Baidu AI Search integration for websearch in China by adding a new provider option, configuration key, and plugin support for the Baidu AI Search MCP server.

New Features:

  • Add support for Baidu AI Search as a websearch provider with dynamic MCP server initialization
  • Introduce a new configuration setting for the Baidu App Builder API key

Enhancements:

  • Update default configuration schema to include "baidu_ai_search" in websearch_provider options and its API key field in provider_settings

@auto-assign auto-assign bot requested review from Larch-C and Raven95676 October 13, 2025 13:22
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好 - 我已审阅你的更改,它们看起来很棒!

AI 代理提示
请处理此代码审查中的评论:

## 单独评论

### 评论 1
<location> `packages/web_searcher/main.py:234-236` </location>
<code_context>
+        if self.baidu_initialized:
+            return
+        cfg = self.context.get_config(umo=umo)
+        key = cfg.get("provider_settings", {}).get(
+            "websearch_baidu_app_builder_key", ""
+        )
+        if not key:
</code_context>

<issue_to_address>
**问题 (typo):** 百度 API 密钥的配置键名可能存在拼写错误。

与 default.py 中的配置键相比,这里的配置键多了一个 'r'。这种不一致会导致初始化失败。请更新键名以使其在所有文件中保持一致。

```suggestion
        key = cfg.get("provider_settings", {}).get(
            "websearch_baidu_app_builde_key", ""
        )
```
</issue_to_address>

### 评论 2
<location> `packages/web_searcher/main.py:241` </location>
<code_context>
+            raise ValueError(
+                "Error: Baidu AI Search API key is not configured in AstrBot."
+            )
+        self.baidu_initialized = True
+        func_tool_mgr = self.context.get_llm_tool_manager()
+        await func_tool_mgr.enable_mcp_server(
</code_context>

<issue_to_address>
**建议 (bug_risk):** 初始化标志在 MCP 服务器启用之前设置。

在 await 调用之后分配 'self.baidu_initialized = True',以避免在 'enable_mcp_server' 失败时将其标记为已初始化。
</issue_to_address>

### 评论 3
<location> `astrbot/core/config/default.py:60` </location>
<code_context>
         "web_search": False,
         "websearch_provider": "default",
         "websearch_tavily_key": [],
+        "webseach_baidu_app_builder_key": "",
         "web_search_link": False,
         "display_reasoning_text": False,
</code_context>

<issue_to_address>
**问题 (typo):** 配置键名拼写错误:'webseach_baidu_app_builder_key' 应该是 'websearch_baidu_app_builder_key'。

拼写错误将导致百度 API 密钥无法正确访问。请修复以避免功能错误。

建议的实现:

```python
        "websearch_baidu_app_builder_key": "",

```

如果文件中的其他地方(例如,在 provider_settings、文档或访问此配置的代码中)引用了 "webseach_baidu_app_builder_key",那么这些引用也应更新为 "websearch_baidu_app_builder_key",以确保一致性和正确的功能。
</issue_to_address>

Sourcery 对开源免费 - 如果你喜欢我们的评论,请考虑分享它们 ✨
帮助我更有用!请点击每个评论上的 👍 或 👎,我将利用这些反馈来改进你的评论。
Original comment in English

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `packages/web_searcher/main.py:234-236` </location>
<code_context>
+        if self.baidu_initialized:
+            return
+        cfg = self.context.get_config(umo=umo)
+        key = cfg.get("provider_settings", {}).get(
+            "websearch_baidu_app_builder_key", ""
+        )
+        if not key:
</code_context>

<issue_to_address>
**issue (typo):** Possible typo in config key name for Baidu API key.

The config key here has an extra 'r' compared to the one in default.py. This inconsistency will cause initialization to fail. Please update the key name to match across all files.

```suggestion
        key = cfg.get("provider_settings", {}).get(
            "websearch_baidu_app_builde_key", ""
        )
```
</issue_to_address>

### Comment 2
<location> `packages/web_searcher/main.py:241` </location>
<code_context>
+            raise ValueError(
+                "Error: Baidu AI Search API key is not configured in AstrBot."
+            )
+        self.baidu_initialized = True
+        func_tool_mgr = self.context.get_llm_tool_manager()
+        await func_tool_mgr.enable_mcp_server(
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Initialization flag is set before MCP server is enabled.

Assign 'self.baidu_initialized = True' after the await call to avoid marking as initialized if 'enable_mcp_server' fails.
</issue_to_address>

### Comment 3
<location> `astrbot/core/config/default.py:60` </location>
<code_context>
         "web_search": False,
         "websearch_provider": "default",
         "websearch_tavily_key": [],
+        "webseach_baidu_app_builder_key": "",
         "web_search_link": False,
         "display_reasoning_text": False,
</code_context>

<issue_to_address>
**issue (typo):** Typo in config key name: 'webseach_baidu_app_builder_key' should be 'websearch_baidu_app_builder_key'.

The misspelling will prevent the Baidu API key from being accessed correctly. Please fix to avoid functional errors.

Suggested implementation:

```python
        "websearch_baidu_app_builder_key": "",

```

If "webseach_baidu_app_builder_key" is referenced elsewhere in the file (e.g., in provider_settings, documentation, or code that accesses this config), those references should also be updated to "websearch_baidu_app_builder_key" to ensure consistency and correct functionality.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Soulter Soulter merged commit 37bdb6c into master Oct 14, 2025
5 checks passed
@Soulter Soulter deleted the feat/websearch_baidu_ai_search branch October 14, 2025 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants