Source code for langchain_community.tools.google_search.tool
"""Tool for the Google search API."""fromtypingimportOptionalfromlangchain_core._api.deprecationimportdeprecatedfromlangchain_core.callbacksimportCallbackManagerForToolRunfromlangchain_core.toolsimportBaseToolfromlangchain_community.utilities.google_searchimportGoogleSearchAPIWrapper
[docs]@deprecated(since="0.0.33",removal="1.0",alternative_import="langchain_google_community.GoogleSearchRun",)classGoogleSearchRun(BaseTool):# type: ignore[override]"""Tool that queries the Google search API."""name:str="google_search"description:str=("A wrapper around Google Search. ""Useful for when you need to answer questions about current events. ""Input should be a search query.")api_wrapper:GoogleSearchAPIWrapperdef_run(self,query:str,run_manager:Optional[CallbackManagerForToolRun]=None,)->str:"""Use the tool."""returnself.api_wrapper.run(query)
[docs]@deprecated(since="0.0.33",removal="1.0",alternative_import="langchain_google_community.GoogleSearchResults",)classGoogleSearchResults(BaseTool):# type: ignore[override]"""Tool that queries the Google Search API and gets back json."""name:str="google_search_results_json"description:str=("A wrapper around Google Search. ""Useful for when you need to answer questions about current events. ""Input should be a search query. Output is a JSON array of the query results")num_results:int=4api_wrapper:GoogleSearchAPIWrapperdef_run(self,query:str,run_manager:Optional[CallbackManagerForToolRun]=None,)->str:"""Use the tool."""returnstr(self.api_wrapper.results(query,self.num_results))