Skip to content

Commit ddd518a

Browse files
authored
searx_search: updated tools and doc (#6276)
- Allows using the same wrapper to create multiple tools ```python wrapper = SearxSearchWrapper(searx_host="**") github_tool = SearxSearchResults(name="Github", wrapper=wrapper, kwargs = { "engines": ["github"], }) arxiv_tool = SearxSearchResults(name="Arxiv", wrapper=wrapper, kwargs = { "engines": ["arxiv"] }) ``` - Updated link to searx documentation Agents / Tools / Toolkits - @hwchase17
1 parent e2f36ee commit ddd518a

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

docs/extras/ecosystem/integrations/searx.mdx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,24 @@ tools = load_tools(["searx-search-results-json"],
6767
num_results=5)
6868
```
6969

70-
For more information on tools, see [this page](/docs/modules/agents/tools/getting_started.md)
70+
#### Quickly creating tools
71+
72+
This examples showcases a quick way to create multiple tools from the same
73+
wrapper.
74+
75+
```python
76+
from langchain.tools.searx_search.tool import SearxSearchResults
77+
78+
wrapper = SearxSearchWrapper(searx_host="**")
79+
github_tool = SearxSearchResults(name="Github", wrapper=wrapper,
80+
kwargs = {
81+
"engines": ["github"],
82+
})
83+
84+
arxiv_tool = SearxSearchResults(name="Arxiv", wrapper=wrapper,
85+
kwargs = {
86+
"engines": ["arxiv"]
87+
})
88+
```
89+
90+
For more information on tools, see [this page](../modules/agents/tools/getting_started.md)

langchain/tools/searx_search/tool.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
AsyncCallbackManagerForToolRun,
88
CallbackManagerForToolRun,
99
)
10-
from langchain.tools.base import BaseTool
10+
from langchain.tools.base import BaseTool, Field
1111
from langchain.utilities.searx_search import SearxSearchWrapper
1212

1313

@@ -21,22 +21,23 @@ class SearxSearchRun(BaseTool):
2121
"Input should be a search query."
2222
)
2323
wrapper: SearxSearchWrapper
24+
kwargs: dict = Field(default_factory=dict)
2425

2526
def _run(
2627
self,
2728
query: str,
2829
run_manager: Optional[CallbackManagerForToolRun] = None,
2930
) -> str:
3031
"""Use the tool."""
31-
return self.wrapper.run(query)
32+
return self.wrapper.run(query, **self.kwargs)
3233

3334
async def _arun(
3435
self,
3536
query: str,
3637
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
3738
) -> str:
3839
"""Use the tool asynchronously."""
39-
return await self.wrapper.arun(query)
40+
return await self.wrapper.arun(query, **self.kwargs)
4041

4142

4243
class SearxSearchResults(BaseTool):
@@ -50,6 +51,7 @@ class SearxSearchResults(BaseTool):
5051
)
5152
wrapper: SearxSearchWrapper
5253
num_results: int = 4
54+
kwargs: dict = Field(default_factory=dict)
5355

5456
class Config:
5557
"""Pydantic config."""
@@ -62,12 +64,14 @@ def _run(
6264
run_manager: Optional[CallbackManagerForToolRun] = None,
6365
) -> str:
6466
"""Use the tool."""
65-
return str(self.wrapper.results(query, self.num_results))
67+
return str(self.wrapper.results(query, self.num_results, **self.kwargs))
6668

6769
async def _arun(
6870
self,
6971
query: str,
7072
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
7173
) -> str:
7274
"""Use the tool asynchronously."""
73-
return (await self.wrapper.aresults(query, self.num_results)).__str__()
75+
return (
76+
await self.wrapper.aresults(query, self.num_results, **self.kwargs)
77+
).__str__()

langchain/utilities/searx_search.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@
120120
use a self hosted instance and disable the rate limiter.
121121
122122
If you are self-hosting an instance you can customize the rate limiter for your
123-
own network as described `here <https://github.com/searxng/searxng/pull/2129>`_.
123+
own network as described
124+
`here <https://docs.searxng.org/src/searx.botdetection.html#limiter-src>`_.
124125
125126
126127
For a list of public SearxNG instances see https://searx.space/

0 commit comments

Comments
 (0)