Skip to content
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

/app/tool: A new tool for Baidu search #386

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/agent/manus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app.tool.file_saver import FileSaver
from app.tool.google_search import GoogleSearch
from app.tool.python_execute import PythonExecute

from app.tool.baidu_search import BaiduSearch

class Manus(ToolCallAgent):
"""
Expand All @@ -29,6 +29,6 @@ class Manus(ToolCallAgent):
# Add general-purpose tools to the tool collection
available_tools: ToolCollection = Field(
default_factory=lambda: ToolCollection(
PythonExecute(), GoogleSearch(), BrowserUseTool(), FileSaver(), Terminate()
PythonExecute(), GoogleSearch(), BaiduSearch(), BrowserUseTool(), FileSaver(), Terminate()
)
)
4 changes: 3 additions & 1 deletion app/prompt/manus.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
BrowserUseTool: Open, browse, and use web browsers.If you open a local HTML file, you must provide the absolute path to the file.
GoogleSearch: Perform web information retrieval
GoogleSearch: Perform web information retrieval using Google search engine.
BaiduSearch: Perform web information retrieval using Baidu search engine, especially effective for Chinese content.
Based on user needs, proactively select the most appropriate tool or combination of tools. For complex tasks, you can break down the problem and use different tools step by step to solve it. After using each tool, clearly explain the execution results and suggest the next steps.
"""
49 changes: 49 additions & 0 deletions app/tool/baidu_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import asyncio
from typing import List
from baidusearch.baidusearch import search
from app.tool.base import BaseTool

class BaiduSearch(BaseTool):
name: str = "baidu_search"
description: str = """Perform a Baidu search and return a list of relevant links.
Use this tool when you need to find information on the web, get up-to-date data, or research specific topics.
The tool returns a list of URLs that match the search query.
"""
parameters: dict = {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "(required) The search query to submit to Baidu.",
},
"num_results": {
"type": "integer",
"description": "(optional) The number of search results to return. Default is 10.",
"default": 10,
},
},
"required": ["query"],
}

async def execute(self, query: str, num_results: int = 10) -> List[str]:
"""
Execute a Baidu search and return a list of URLs.
Args:
query (str): The search query to submit to Baidu.
num_results (int, optional): The number of search results to return. Default is 10.
Returns:
List[str]: A list of URLs matching the search query.
"""
# Run the search in a thread pool to prevent blocking
loop = asyncio.get_event_loop()
response = await loop.run_in_executor(
None, lambda: search(query, num_results=num_results)
)
links = []
for item in response:
url = item['url']
if url.startswith('http'):
links.append(url)
return links