Source code for langchain_community.tools.dataforseo_api_search.tool
"""Tool for the DataForSeo SERP API."""fromtypingimportOptionalfromlangchain_core.callbacksimport(AsyncCallbackManagerForToolRun,CallbackManagerForToolRun,)fromlangchain_core.toolsimportBaseToolfrompydanticimportFieldfromlangchain_community.utilities.dataforseo_api_searchimportDataForSeoAPIWrapper
[docs]classDataForSeoAPISearchRun(BaseTool):# type: ignore[override]"""Tool that queries the DataForSeo Google search API."""name:str="dataforseo_api_search"description:str=("A robust Google Search API provided by DataForSeo.""This tool is handy when you need information about trending topics ""or current events.")api_wrapper:DataForSeoAPIWrapperdef_run(self,query:str,run_manager:Optional[CallbackManagerForToolRun]=None,)->str:"""Use the tool."""returnstr(self.api_wrapper.run(query))asyncdef_arun(self,query:str,run_manager:Optional[AsyncCallbackManagerForToolRun]=None,)->str:"""Use the tool asynchronously."""return(awaitself.api_wrapper.arun(query)).__str__()
[docs]classDataForSeoAPISearchResults(BaseTool):# type: ignore[override]"""Tool that queries the DataForSeo Google Search API and get back json."""name:str="dataforseo_results_json"description:str=("A comprehensive Google Search API provided by DataForSeo.""This tool is useful for obtaining real-time data on current events ""or popular searches.""The input should be a search query and the output is a JSON object ""of the query results.")api_wrapper:DataForSeoAPIWrapper=Field(default_factory=DataForSeoAPIWrapper)def_run(self,query:str,run_manager:Optional[CallbackManagerForToolRun]=None,)->str:"""Use the tool."""returnstr(self.api_wrapper.results(query))asyncdef_arun(self,query:str,run_manager:Optional[AsyncCallbackManagerForToolRun]=None,)->str:"""Use the tool asynchronously."""return(awaitself.api_wrapper.aresults(query)).__str__()