mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-11 07:25:29 +00:00
improve duck duck go tool (#13165)
This commit is contained in:
parent
850336bcf1
commit
0a2b1c7471
@ -1,14 +1,18 @@
|
|||||||
"""Tool for the DuckDuckGo search API."""
|
"""Tool for the DuckDuckGo search API."""
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional, Type
|
||||||
|
|
||||||
from langchain.callbacks.manager import CallbackManagerForToolRun
|
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.tools.base import BaseTool
|
||||||
from langchain.utilities.duckduckgo_search import DuckDuckGoSearchAPIWrapper
|
from langchain.utilities.duckduckgo_search import DuckDuckGoSearchAPIWrapper
|
||||||
|
|
||||||
|
|
||||||
|
class DDGInput(BaseModel):
|
||||||
|
query: str = Field(description="search query to look up")
|
||||||
|
|
||||||
|
|
||||||
class DuckDuckGoSearchRun(BaseTool):
|
class DuckDuckGoSearchRun(BaseTool):
|
||||||
"""Tool that queries the DuckDuckGo search API."""
|
"""Tool that queries the DuckDuckGo search API."""
|
||||||
|
|
||||||
@ -21,6 +25,7 @@ class DuckDuckGoSearchRun(BaseTool):
|
|||||||
api_wrapper: DuckDuckGoSearchAPIWrapper = Field(
|
api_wrapper: DuckDuckGoSearchAPIWrapper = Field(
|
||||||
default_factory=DuckDuckGoSearchAPIWrapper
|
default_factory=DuckDuckGoSearchAPIWrapper
|
||||||
)
|
)
|
||||||
|
args_schema: Type[BaseModel] = DDGInput
|
||||||
|
|
||||||
def _run(
|
def _run(
|
||||||
self,
|
self,
|
||||||
@ -45,6 +50,7 @@ class DuckDuckGoSearchResults(BaseTool):
|
|||||||
default_factory=DuckDuckGoSearchAPIWrapper
|
default_factory=DuckDuckGoSearchAPIWrapper
|
||||||
)
|
)
|
||||||
backend: str = "api"
|
backend: str = "api"
|
||||||
|
args_schema: Type[BaseModel] = DDGInput
|
||||||
|
|
||||||
def _run(
|
def _run(
|
||||||
self,
|
self,
|
||||||
|
Loading…
Reference in New Issue
Block a user