mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-17 07:26:16 +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:
@@ -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