mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-14 05:56:40 +00:00
community[minor]: add mojeek search util (#20922)
**Description:** This pull request introduces a new feature to community tools, enhancing its search capabilities by integrating the Mojeek search engine **Dependencies:** None --------- Co-authored-by: Igor Brai <igor@mojeek.com> Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: ccurme <chester.curme@gmail.com>
This commit is contained in:
@@ -157,6 +157,9 @@ if TYPE_CHECKING:
|
||||
from langchain_community.tools.metaphor_search import (
|
||||
MetaphorSearchResults, # noqa: F401
|
||||
)
|
||||
from langchain_community.tools.mojeek_search.tool import (
|
||||
MojeekSearch, # noqa: F401
|
||||
)
|
||||
from langchain_community.tools.nasa.tool import (
|
||||
NasaAction, # noqa: F401
|
||||
)
|
||||
@@ -385,6 +388,7 @@ __all__ = [
|
||||
"ListSparkSQLTool",
|
||||
"MerriamWebsterQueryRun",
|
||||
"MetaphorSearchResults",
|
||||
"MojeekSearch",
|
||||
"MoveFileTool",
|
||||
"NasaAction",
|
||||
"NavigateBackTool",
|
||||
@@ -528,6 +532,7 @@ _module_lookup = {
|
||||
"ListSparkSQLTool": "langchain_community.tools.spark_sql.tool",
|
||||
"MerriamWebsterQueryRun": "langchain_community.tools.merriam_webster.tool",
|
||||
"MetaphorSearchResults": "langchain_community.tools.metaphor_search",
|
||||
"MojeekSearch": "langchain_community.tools.mojeek_search.tool",
|
||||
"MoveFileTool": "langchain_community.tools.file_management",
|
||||
"NasaAction": "langchain_community.tools.nasa.tool",
|
||||
"NavigateBackTool": "langchain_community.tools.playwright",
|
||||
|
@@ -0,0 +1,45 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Optional
|
||||
|
||||
from langchain_core.callbacks import (
|
||||
AsyncCallbackManagerForToolRun,
|
||||
CallbackManagerForToolRun,
|
||||
)
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
from langchain_community.utilities.mojeek_search import MojeekSearchAPIWrapper
|
||||
|
||||
|
||||
class MojeekSearch(BaseTool):
|
||||
name: str = "mojeek_search"
|
||||
description: str = (
|
||||
"A wrapper around Mojeek Search. "
|
||||
"Useful for when you need to web search results. "
|
||||
"Input should be a search query."
|
||||
)
|
||||
api_wrapper: MojeekSearchAPIWrapper
|
||||
|
||||
@classmethod
|
||||
def config(
|
||||
cls, api_key: str, search_kwargs: Optional[dict] = None, **kwargs: Any
|
||||
) -> MojeekSearch:
|
||||
wrapper = MojeekSearchAPIWrapper(
|
||||
api_key=api_key, search_kwargs=search_kwargs or {}
|
||||
)
|
||||
return cls(api_wrapper=wrapper, **kwargs)
|
||||
|
||||
def _run(
|
||||
self,
|
||||
query: str,
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
return self.api_wrapper.run(query)
|
||||
|
||||
async def _arun(
|
||||
self,
|
||||
query: str,
|
||||
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
"""Use the tool asynchronously."""
|
||||
raise NotImplementedError("MojeekSearch does not support async")
|
Reference in New Issue
Block a user