-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: 内置网页搜索功能支持接入百度 AI 搜索 #3031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
Contributor
There was a problem hiding this 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>帮助我更有用!请点击每个评论上的 👍 或 👎,我将利用这些反馈来改进你的评论。
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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Motivation / 动机
提高 websearch 在中国大陆的可用性
Modifications / 改动点
增加了一个配置项配置 appbuilder api key
修改了 websearch 内置插件
Verification Steps / 验证步骤
Screenshots or Test Results / 运行截图或测试结果
Compatibility & Breaking Changes / 兼容性与破坏性变更
Checklist / 检查清单
above.
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR ifnew dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml.Sourcery 总结
通过添加新的提供商选项、配置密钥以及对百度 AI 搜索 MCP 服务器的插件支持,为在中国的网页搜索启用百度 AI 搜索集成。
新功能:
增强功能:
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:
Enhancements: