-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: add web search command using WebSurferAgent for enhanced resear… #3
Conversation
Walkthrough此次变更主要涉及三个方面:
Changes
Sequence Diagram(s)sequenceDiagram
participant U as 用户
participant D as Discord Bot
participant G as WebSearchCogs
participant W as WebSurferAgent
U->>D: 发送 "web" 指令与提示文本
D->>G: 将指令和参数转发至 WebSearchCogs
G->>W: 初始化 WebSurferAgent 并调用 run 方法
W-->>G: 返回网页搜索的结果摘要
G->>D: 将搜索结果发送回 Discord 频道
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pyproject.toml (1)
69-69
: 建议指定更严格的版本约束当前的版本约束
"ag2[browser-use]>=0.7.2"
可能会在新版本发布时导致不兼容问题。建议使用更严格的版本约束。建议修改为:
- "ag2[browser-use]>=0.7.2", + "ag2[browser-use]>=0.7.2,<0.8.0",
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
uv.lock
is excluded by!**/*.lock
📒 Files selected for processing (3)
.python-version
(1 hunks)pyproject.toml
(2 hunks)src/cogs/gen_search.py
(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- .python-version
🔇 Additional comments (1)
pyproject.toml (1)
198-198
: 验证预发布设置的影响更新后的
prerelease = "if-necessary-or-explicit"
设置可能会影响依赖项的安装稳定性。✅ Verification successful
🌐 Web query:
uv package manager prerelease setting "if-necessary-or-explicit" vs "if-necessary" difference
💡 Result:
The
prerelease
setting in uv controls how pre-release package versions are handled during dependency resolution. Here's the key difference betweenif-necessary-or-explicit
andif-necessary
:Prerelease Handling Strategies
1.
if-necessary
- Allows pre-releases only when:
- All available versions of a package are pre-releases[1][6][9]
- No stable releases exist for the package[1][6]
2.
if-necessary-or-explicit
(Default)
Adds an additional condition toif-necessary
:
- Allows pre-releases when:
- All versions are pre-releases (same as
if-necessary
)- OR first-party requirements explicitly specify a pre-release version using markers like:
package==2.1.0rc1
package>=2.1.0a0
[1][6][9]Key Comparison
Strategy Accepts Pre-Releases When... Explicit Specifiers Required? if-necessary
Only when no stable versions exist No if-necessary-or-explicit
No stable versions OR explicit pre-release markers in requirements Yes for non-emergency cases This means
if-necessary-or-explicit
provides more flexibility by allowing intentional adoption of pre-releases through explicit version specifiers, while still preventing accidental use of unstable versions[1][6]. The default setting helps balance stability with access to cutting-edge features when explicitly requested[9].Citations:
- 1: https://docs.astral.sh/uv/reference/settings/
- 2: https://flocode.substack.com/p/044-python-environments-again-uv
- 3: https://zenn.dev/kun432/scraps/6a16be7be8e53e
- 4: https://docs.unity3d.com/2023.2/Documentation/Manual/pack-preview.html
- 5: https://discuss.python.org/t/uv-another-rust-tool-written-to-replace-pip/46039
- 6: https://github.com/astral-sh/uv/blob/main/uv.schema.json
- 7: https://www.janestreet.com/tech-talks/uv-an-extremely-fast-python-package-manager/
- 8: Best practices for
requires-python
astral-sh/uv#7429- 9: https://docs.astral.sh/uv/reference/cli/
- 10: https://docs.unity3d.com/2023.2/Documentation/Manual/class-PackageManager.html
确认预发布设置变更影响
根据 uv 官方文档及相关说明,
if-necessary-or-explicit
与if-necessary
的主要区别在于:
if-necessary
:仅当包的所有可用版本都是预发布版本(即没有稳定版本)时才允许安装预发布版本。if-necessary-or-explicit
:在上述条件成立的情况下,同样允许安装预发布版本,同时在依赖项中若显式指定了预发布版本(例如package==2.1.0rc1
或package>=2.1.0a0
),也会允许安装预发布版本。因此,更新后的配置
prerelease = "if-necessary-or-explicit"
增加了对显式指定预发布依赖的支持,可能会在某些情况下引入预发布版本,从而影响依赖项安装的稳定性。请注意这一行为是否符合项目预期。
@commands.command() | ||
async def web(self, ctx: commands.Context, *, prompt: str) -> None: | ||
llm_config = {"model": "gpt-4o-mini"} | ||
browser_use_browser_config = { | ||
"browser_config": {"headless": True}, | ||
"agent_kwargs": {"generate_gif": True}, | ||
} | ||
web_researcher = WebSurferAgent( | ||
name="researcher", | ||
llm_config=llm_config, | ||
human_input_mode="NEVER", | ||
web_tool="browser_use", | ||
web_tool_kwargs=browser_use_browser_config, | ||
) | ||
ag2_news_result = web_researcher.run(message=prompt, tools=web_researcher.tools, user_input=False) | ||
ctx.send(content=ag2_news_result.summary) | ||
|
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.
需要添加错误处理和改进实现
该实现存在以下问题:
- 缺少错误处理机制,可能导致未捕获的异常
- Discord消息发送方法使用错误,
ctx.send()
需要使用await
- 硬编码的模型名称 "gpt-4o-mini" 可能存在风险
建议按照以下方式修改代码:
@commands.command()
async def web(self, ctx: commands.Context, *, prompt: str) -> None:
- llm_config = {"model": "gpt-4o-mini"}
+ llm_config = {"model": "gpt-3.5-turbo"} # 使用稳定的模型
browser_use_browser_config = {
"browser_config": {"headless": True},
"agent_kwargs": {"generate_gif": True},
}
- web_researcher = WebSurferAgent(
- name="researcher",
- llm_config=llm_config,
- human_input_mode="NEVER",
- web_tool="browser_use",
- web_tool_kwargs=browser_use_browser_config,
- )
- ag2_news_result = web_researcher.run(message=prompt, tools=web_researcher.tools, user_input=False)
- ctx.send(content=ag2_news_result.summary)
+ try:
+ web_researcher = WebSurferAgent(
+ name="researcher",
+ llm_config=llm_config,
+ human_input_mode="NEVER",
+ web_tool="browser_use",
+ web_tool_kwargs=browser_use_browser_config,
+ )
+ ag2_news_result = await web_researcher.run(
+ message=prompt,
+ tools=web_researcher.tools,
+ user_input=False
+ )
+ await ctx.send(content=ag2_news_result.summary)
+ except Exception as e:
+ await ctx.send(content=f"搜索时发生错误: {e!s}")
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
@commands.command() | |
async def web(self, ctx: commands.Context, *, prompt: str) -> None: | |
llm_config = {"model": "gpt-4o-mini"} | |
browser_use_browser_config = { | |
"browser_config": {"headless": True}, | |
"agent_kwargs": {"generate_gif": True}, | |
} | |
web_researcher = WebSurferAgent( | |
name="researcher", | |
llm_config=llm_config, | |
human_input_mode="NEVER", | |
web_tool="browser_use", | |
web_tool_kwargs=browser_use_browser_config, | |
) | |
ag2_news_result = web_researcher.run(message=prompt, tools=web_researcher.tools, user_input=False) | |
ctx.send(content=ag2_news_result.summary) | |
@commands.command() | |
async def web(self, ctx: commands.Context, *, prompt: str) -> None: | |
llm_config = {"model": "gpt-3.5-turbo"} # 使用稳定的模型 | |
browser_use_browser_config = { | |
"browser_config": {"headless": True}, | |
"agent_kwargs": {"generate_gif": True}, | |
} | |
try: | |
web_researcher = WebSurferAgent( | |
name="researcher", | |
llm_config=llm_config, | |
human_input_mode="NEVER", | |
web_tool="browser_use", | |
web_tool_kwargs=browser_use_browser_config, | |
) | |
ag2_news_result = await web_researcher.run( | |
message=prompt, | |
tools=web_researcher.tools, | |
user_input=False | |
) | |
await ctx.send(content=ag2_news_result.summary) | |
except Exception as e: | |
await ctx.send(content=f"搜索时发生错误: {e!s}") |
…ch capabilities
What does this PR do?
Fixes #<issue_number>
Before submitting
pytest
command?pre-commit run -a
command?Did you have fun?
Make sure you had fun coding 🙃
Summary by CodeRabbit
新功能
Chores