agentscope.service.web.search module

Search question in the web

Search question in Bing Search API and return the searching results

Parameters:
Returns:

A dictionary with two variables: status and content. The status variable is from the ServiceExecStatus enum, and content is a list of search results or error information, which depends on the status variable. For each searching result, it is a dictionary with keys ‘title’, ‘link’, and ‘snippet’.

Return type:

ServiceResponse

Example

results = bing_search(question="What is an agent?",
                     bing_api_key="your bing api key",
                     num_results=2,
                     mkt="en-US")
print(results)

It returns the following dict.

{
    'status': <ServiceExecStatus.SUCCESS: 1>,
    'content': [
        {
            'title': 'What Is an Agent? Definition, Types of
                Agents, and Examples - Investopedia',
            'link':
            'https://www.investopedia.com/terms/a/agent.asp',
            'snippet': "An agent is someone that is given
                permission (either explicitly or assumed) to act
                on an individual's behalf and may do so in a
                variety of capacities. This could include
                selling a home, executing..."},
        {
            'title': 'AGENT Definition & Usage Examples |
                        Dictionary.com',
            'link': 'https://www.dictionary.com/browse/agent',
            'snippet': 'noun. a person who acts on behalf of
                another person, group, business, government,
                etc; representative. a person or thing that acts
                or has the power to act. a phenomenon,
                substance, or organism that exerts some force or
                effect: a chemical agent.'
        }
    ]
}

Search question in Google Search API and return the searching results

Parameters:
  • question (str) – The search query string.

  • api_key (str) – The API key provided for authenticating with the Google Custom Search JSON API.

  • cse_id (str) – The unique identifier of a programmable search engine to use.

  • num_results (int, defaults to 10) – The number of search results to return.

  • **kwargs (Any) – Additional keyword arguments to be included in the search query. For more details, please refer to https://developers.google.com/custom-search/v1/reference/rest/v1/cse/list

Returns:

A dictionary with two variables: status and content. The status variable is from the ServiceExecStatus enum, and content is a list of search results or error information, which depends on the status variable. For each searching result, it is a dictionary with keys ‘title’, ‘link’, and ‘snippet’.

Return type:

ServiceResponse

Example

results = google_search(
    'Python programming',
    'your_google_api_key',
    'your_cse_id',
    num_results=2
)
if results.status == ServiceExecStatus.SUCCESS:
    for result in results.content:
        print(result['title'], result['link'], result['snippet'])