|
|
|
@ -7,7 +7,7 @@ from langchain.callbacks.manager import (
|
|
|
|
|
AsyncCallbackManagerForToolRun,
|
|
|
|
|
CallbackManagerForToolRun,
|
|
|
|
|
)
|
|
|
|
|
from langchain.tools.base import BaseTool
|
|
|
|
|
from langchain.tools.base import BaseTool, Field
|
|
|
|
|
from langchain.utilities.searx_search import SearxSearchWrapper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -21,6 +21,7 @@ class SearxSearchRun(BaseTool):
|
|
|
|
|
"Input should be a search query."
|
|
|
|
|
)
|
|
|
|
|
wrapper: SearxSearchWrapper
|
|
|
|
|
kwargs: dict = Field(default_factory=dict)
|
|
|
|
|
|
|
|
|
|
def _run(
|
|
|
|
|
self,
|
|
|
|
@ -28,7 +29,7 @@ class SearxSearchRun(BaseTool):
|
|
|
|
|
run_manager: Optional[CallbackManagerForToolRun] = None,
|
|
|
|
|
) -> str:
|
|
|
|
|
"""Use the tool."""
|
|
|
|
|
return self.wrapper.run(query)
|
|
|
|
|
return self.wrapper.run(query, **self.kwargs)
|
|
|
|
|
|
|
|
|
|
async def _arun(
|
|
|
|
|
self,
|
|
|
|
@ -36,7 +37,7 @@ class SearxSearchRun(BaseTool):
|
|
|
|
|
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
|
|
|
|
|
) -> str:
|
|
|
|
|
"""Use the tool asynchronously."""
|
|
|
|
|
return await self.wrapper.arun(query)
|
|
|
|
|
return await self.wrapper.arun(query, **self.kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SearxSearchResults(BaseTool):
|
|
|
|
@ -50,6 +51,7 @@ class SearxSearchResults(BaseTool):
|
|
|
|
|
)
|
|
|
|
|
wrapper: SearxSearchWrapper
|
|
|
|
|
num_results: int = 4
|
|
|
|
|
kwargs: dict = Field(default_factory=dict)
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
"""Pydantic config."""
|
|
|
|
@ -62,7 +64,7 @@ class SearxSearchResults(BaseTool):
|
|
|
|
|
run_manager: Optional[CallbackManagerForToolRun] = None,
|
|
|
|
|
) -> str:
|
|
|
|
|
"""Use the tool."""
|
|
|
|
|
return str(self.wrapper.results(query, self.num_results))
|
|
|
|
|
return str(self.wrapper.results(query, self.num_results, **self.kwargs))
|
|
|
|
|
|
|
|
|
|
async def _arun(
|
|
|
|
|
self,
|
|
|
|
@ -70,4 +72,6 @@ class SearxSearchResults(BaseTool):
|
|
|
|
|
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
|
|
|
|
|
) -> str:
|
|
|
|
|
"""Use the tool asynchronously."""
|
|
|
|
|
return (await self.wrapper.aresults(query, self.num_results)).__str__()
|
|
|
|
|
return (
|
|
|
|
|
await self.wrapper.aresults(query, self.num_results, **self.kwargs)
|
|
|
|
|
).__str__()
|
|
|
|
|