Skip to main content

browser_utils.markdown_search

AbstractMarkdownSearch

class AbstractMarkdownSearch(ABC)

An abstract class for providing search capabilities to a Markdown browser.

BingMarkdownSearch

class BingMarkdownSearch(AbstractMarkdownSearch)

Provides Bing web search capabilities to Markdown browsers.

__init__

def __init__(bing_api_key: str = None, interleave_results: bool = True)

Perform a Bing web search, and return the results formatted in Markdown.

Arguments:

  • bing_api_key - key for the Bing search API. If omitted, an attempt is made to read the key from the BING_API_KEY environment variable. If no key is found, BingMarkdownSearch will print a warning, and will fall back to visiting and scraping the live Bing results page. Scraping is objectively worse than using the API, and thus is not recommended.
  • interleave_results - When using the Bing API, results are returned based on category (web, news, videos, etc.), along with instructions for how they should be interleaved on the page. When interleave is set to True, these interleaving instructions are followed, and a single results list is returned by BingMarkdownSearch. When interleave is set to false, results are separated by category, and no interleaving is done.
def search(query: str)

Search Bing and return the results formatted in Markdown. If a Bing API key is available, the API is used to perform the search. If no API key is available, the search is performed by submitting an HTTPs GET request directly to Bing. Searches performed with the API are much higher quality, and are more reliable.

Arguments:

  • query - The search query to issue

Returns:

A Markdown rendering of the search results.