|
|
|
@ -1,14 +1,18 @@
|
|
|
|
|
"""Tool for the DuckDuckGo search API."""
|
|
|
|
|
|
|
|
|
|
import warnings
|
|
|
|
|
from typing import Any, Optional
|
|
|
|
|
from typing import Any, Optional, Type
|
|
|
|
|
|
|
|
|
|
from langchain.callbacks.manager import CallbackManagerForToolRun
|
|
|
|
|
from langchain.pydantic_v1 import Field
|
|
|
|
|
from langchain.pydantic_v1 import BaseModel, Field
|
|
|
|
|
from langchain.tools.base import BaseTool
|
|
|
|
|
from langchain.utilities.duckduckgo_search import DuckDuckGoSearchAPIWrapper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DDGInput(BaseModel):
|
|
|
|
|
query: str = Field(description="search query to look up")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DuckDuckGoSearchRun(BaseTool):
|
|
|
|
|
"""Tool that queries the DuckDuckGo search API."""
|
|
|
|
|
|
|
|
|
@ -21,6 +25,7 @@ class DuckDuckGoSearchRun(BaseTool):
|
|
|
|
|
api_wrapper: DuckDuckGoSearchAPIWrapper = Field(
|
|
|
|
|
default_factory=DuckDuckGoSearchAPIWrapper
|
|
|
|
|
)
|
|
|
|
|
args_schema: Type[BaseModel] = DDGInput
|
|
|
|
|
|
|
|
|
|
def _run(
|
|
|
|
|
self,
|
|
|
|
@ -45,6 +50,7 @@ class DuckDuckGoSearchResults(BaseTool):
|
|
|
|
|
default_factory=DuckDuckGoSearchAPIWrapper
|
|
|
|
|
)
|
|
|
|
|
backend: str = "api"
|
|
|
|
|
args_schema: Type[BaseModel] = DDGInput
|
|
|
|
|
|
|
|
|
|
def _run(
|
|
|
|
|
self,
|
|
|
|
|