mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
b3e74f2b98
**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>
46 lines
1.3 KiB
Python
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")
|