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 Bing search #385

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

via007
Copy link

@via007 via007 commented Mar 10, 2025

Title: Add BingSearch Tool for Web Search Functionality

Description:
This PR introduces a new BingSearch class to the project, enabling asynchronous Bing search capabilities as part of the BaseTool ecosystem. The tool allows users to perform web searches on Bing and retrieve a list of relevant URLs based on a given query.

Features:

  • Implements BaseTool interface with name, description, and parameters for consistency.
  • Uses requests and BeautifulSoup to scrape Bing search results.
  • Supports asynchronous execution via asyncio.run_in_executor.
  • Returns a list of URLs (up to a specified num_results, defaulting to 10).
  • Handles pagination to fetch multiple pages if needed.

Motivation:

This addition expands the project's search capabilities beyond existing tools (e.g., Google Search) by integrating Bing, providing an alternative source for web data. It’s particularly useful for users needing diverse search results or when other search APIs are unavailable.

Implementation:

  • The class initializes a requests.Session for persistent HTTP connections.
  • The _search_sync method performs the synchronous search logic, wrapped in execute for async support.
  • HTML parsing targets Bing’s <ol id="b_results"> and <li class="b_algo"> structure.
  • Error handling ensures robustness by returning an empty list on failures.

Usage Example:

from bingsearch import BingSearch
import asyncio

async def main():
    tool = BingSearch()
    results = await tool(query="python", num_results=3)
    for i, url in enumerate(results, 1):
        print(f"{i}. {url}")

asyncio.run(main())

@FujiwaraChoki
Copy link

FujiwaraChoki commented Mar 10, 2025

Nice idea! Please update the Agent file as well to integrate this search.

Copy link

@FujiwaraChoki FujiwaraChoki left a comment

Choose a reason for hiding this comment

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

LGTM overall except for a few fixes. Thanks for your contribution.

Copy link

@FujiwaraChoki FujiwaraChoki left a comment

Choose a reason for hiding this comment

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

LGTM, will approve once this comment has been improved

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