From 37b68dc8f22e516c2f3e0f2df58d7fc97d146e2f Mon Sep 17 00:00:00 2001 From: kayvane1 Date: Mon, 24 Apr 2023 11:14:57 +0100 Subject: [PATCH] feat: aligning the tools available for agents to switch between Bing, DDG and Google. All three services now have the same tools and implementations --- langchain/tools/bing_search/tool.py | 20 ++++++++++++++++++++ langchain/tools/ddg_search/tool.py | 24 +++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/langchain/tools/bing_search/tool.py b/langchain/tools/bing_search/tool.py index c851c3ee845..f4df92d6613 100644 --- a/langchain/tools/bing_search/tool.py +++ b/langchain/tools/bing_search/tool.py @@ -22,3 +22,23 @@ class BingSearchRun(BaseTool): async def _arun(self, query: str) -> str: """Use the tool asynchronously.""" raise NotImplementedError("BingSearchRun does not support async") + +class BingSearchResults(BaseTool): + """Tool that has capability to query the Bing Search API and get back json.""" + + name = "DuckDuckGo Results JSON" + description = ( + "A wrapper around Duck Duck Go 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 = 4 + api_wrapper: BingSearchAPIWrapper + + def _run(self, query: str) -> str: + """Use the tool.""" + return str(self.api_wrapper.results(query, self.num_results)) + + async def _arun(self, query: str) -> str: + """Use the tool asynchronously.""" + raise NotImplementedError("BingSearchResults does not support async") \ No newline at end of file diff --git a/langchain/tools/ddg_search/tool.py b/langchain/tools/ddg_search/tool.py index 33044241c4b..473fc7d2b63 100644 --- a/langchain/tools/ddg_search/tool.py +++ b/langchain/tools/ddg_search/tool.py @@ -6,7 +6,7 @@ from langchain.tools.base import BaseTool from langchain.utilities.duckduckgo_search import DuckDuckGoSearchAPIWrapper -class DuckDuckGoSearchTool(BaseTool): +class DuckDuckGoSearchRun(BaseTool): """Tool that adds the capability to query the DuckDuckGo search API.""" name = "DuckDuckGo Search" @@ -26,3 +26,25 @@ class DuckDuckGoSearchTool(BaseTool): async def _arun(self, query: str) -> str: """Use the tool asynchronously.""" raise NotImplementedError("DuckDuckGoSearch does not support async") + +class DuckDuckGoSearchResults(BaseTool): + """Tool that has capability to query the Google Search API and get back json.""" + + name = "DuckDuckGo Results JSON" + description = ( + "A wrapper around Duck Duck Go 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 = 4 + api_wrapper: DuckDuckGoSearchAPIWrapper = Field( + default_factory=DuckDuckGoSearchAPIWrapper + ) + + def _run(self, query: str) -> str: + """Use the tool.""" + return str(self.api_wrapper.results(query, self.num_results)) + + async def _arun(self, query: str) -> str: + """Use the tool asynchronously.""" + raise NotImplementedError("BingSearchResults does not support async") \ No newline at end of file