mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-08-27 19:29:56 -04:00
d2520a5f1e
Co-authored-by: itai <itai.marks@gmail.com> Co-authored-by: Itai Marks <itaim@users.noreply.github.com> Co-authored-by: Tianyi Pan <60060750+tipani86@users.noreply.github.com> Co-authored-by: Tianyi Pan <tianyi.pan@clobotics.com> Co-authored-by: Adilzhan Ismailov <13088690+aismlv@users.noreply.github.com> Co-authored-by: Justin Flick <Justinjayflick@gmail.com> Co-authored-by: Justin Flick <jflick@homesite.com>
29 lines
919 B
Python
29 lines
919 B
Python
"""Tool for the DuckDuckGo search API."""
|
|
|
|
from pydantic import Field
|
|
|
|
from langchain.tools.base import BaseTool
|
|
from langchain.utilities.duckduckgo_search import DuckDuckGoSearchAPIWrapper
|
|
|
|
|
|
class DuckDuckGoSearchTool(BaseTool):
|
|
"""Tool that adds the capability to query the DuckDuckGo search API."""
|
|
|
|
name = "DuckDuckGo Search"
|
|
description = (
|
|
"A wrapper around DuckDuckGo Search. "
|
|
"Useful for when you need to answer questions about current events. "
|
|
"Input should be a search query."
|
|
)
|
|
api_wrapper: DuckDuckGoSearchAPIWrapper = Field(
|
|
default_factory=DuckDuckGoSearchAPIWrapper
|
|
)
|
|
|
|
def _run(self, query: str) -> str:
|
|
"""Use the tool."""
|
|
return self.api_wrapper.run(query)
|
|
|
|
async def _arun(self, query: str) -> str:
|
|
"""Use the tool asynchronously."""
|
|
raise NotImplementedError("DuckDuckGoSearch does not support async")
|