mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-18 16:16:33 +00:00
Align names of search tools (#3620)
Tools for Bing, DDG and Google weren't consistent even though the underlying implementations were. All three services now have the same tools and implementations to easily switch and experiment when building chains.
This commit is contained in:
@@ -1,19 +1,27 @@
|
||||
"""Core toolkit implementations."""
|
||||
|
||||
from langchain.tools.base import BaseTool
|
||||
from langchain.tools.ddg_search.tool import DuckDuckGoSearchTool
|
||||
from langchain.tools.bing_search.tool import BingSearchResults, BingSearchRun
|
||||
from langchain.tools.ddg_search.tool import DuckDuckGoSearchResults, DuckDuckGoSearchRun
|
||||
from langchain.tools.google_places.tool import GooglePlacesTool
|
||||
from langchain.tools.google_search.tool import GoogleSearchResults, GoogleSearchRun
|
||||
from langchain.tools.ifttt import IFTTTWebhook
|
||||
from langchain.tools.openapi.utils.api_models import APIOperation
|
||||
from langchain.tools.openapi.utils.openapi_utils import OpenAPISpec
|
||||
from langchain.tools.plugin import AIPluginTool
|
||||
|
||||
__all__ = [
|
||||
"BaseTool",
|
||||
"IFTTTWebhook",
|
||||
"AIPluginTool",
|
||||
"OpenAPISpec",
|
||||
"APIOperation",
|
||||
"BingSearchResults",
|
||||
"BingSearchRun",
|
||||
"DuckDuckGoSearchResults",
|
||||
"DuckDuckGoSearchRun",
|
||||
"DuckDuckGoSearchRun",
|
||||
"GooglePlacesTool",
|
||||
"DuckDuckGoSearchTool",
|
||||
"GoogleSearchResults",
|
||||
"GoogleSearchRun",
|
||||
"IFTTTWebhook",
|
||||
"OpenAPISpec",
|
||||
"BaseTool",
|
||||
]
|
||||
|
@@ -22,3 +22,24 @@ 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 = "Bing Search Results JSON"
|
||||
description = (
|
||||
"A wrapper around Bing 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")
|
||||
|
@@ -1,5 +1,5 @@
|
||||
"""DuckDuckGo Search API toolkit."""
|
||||
|
||||
from langchain.tools.ddg_search.tool import DuckDuckGoSearchTool
|
||||
from langchain.tools.ddg_search.tool import DuckDuckGoSearchRun
|
||||
|
||||
__all__ = ["DuckDuckGoSearchTool"]
|
||||
__all__ = ["DuckDuckGoSearchRun"]
|
||||
|
@@ -1,12 +1,15 @@
|
||||
"""Tool for the DuckDuckGo search API."""
|
||||
|
||||
import warnings
|
||||
from typing import Any
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
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 +29,35 @@ 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 queries the Duck Duck Go 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("DuckDuckGoSearchResults does not support async")
|
||||
|
||||
|
||||
def DuckDuckGoSearchTool(*args: Any, **kwargs: Any) -> DuckDuckGoSearchRun:
|
||||
warnings.warn(
|
||||
"DuckDuckGoSearchTool will be deprecated in the future. "
|
||||
"Please use DuckDuckGoSearchRun instead.",
|
||||
DeprecationWarning,
|
||||
)
|
||||
return DuckDuckGoSearchRun(*args, **kwargs)
|
||||
|
Reference in New Issue
Block a user