Skip to content

Commit

Permalink
feat: add web search command using WebSurferAgent for enhanced resear…
Browse files Browse the repository at this point in the history
…ch capabilities
  • Loading branch information
Mai0313 committed Feb 11, 2025
1 parent fcdcf30 commit 72068b8
Show file tree
Hide file tree
Showing 4 changed files with 1,426 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.10.14
3.11
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ authors = [
{ name = "Wei", email = "[email protected]" },
]
dependencies = [
"autogen>=0.7.2",
"ag2[browser-use]>=0.7.2",
"discord-py>=2.4.0",
"logfire>=3.4.0",
"openai>=1.60.2",
Expand Down Expand Up @@ -195,7 +195,7 @@ link-mode = "copy"
native-tls = false
no-binary = false
offline = false
prerelease = "if-necessary"
prerelease = "if-necessary-or-explicit"
preview = true

# https://docs.astral.sh/uv/reference/settings/#index
Expand Down
18 changes: 18 additions & 0 deletions src/cogs/gen_search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from discord.ext import commands
from autogen.agents import WebSurferAgent

from src.sdk.llm import LLMServices

Expand All @@ -16,6 +17,23 @@ async def search(self, ctx: commands.Context, *, prompt: str) -> None:
except Exception as e:
await ctx.send(content=f"搜尋時發生錯誤: {e!s}")

@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)


# 註冊 Cog
async def setup(bot: commands.Bot) -> None:
Expand Down
Loading

0 comments on commit 72068b8

Please sign in to comment.