langchain/libs/community/langchain_community/tools/mojeek_search/tool.py
Igor Brai b3e74f2b98
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>
2024-04-29 15:49:53 +00:00

46 lines
1.3 KiB
Python

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")