File size: 864 Bytes
37edd1e 19c2c13 37edd1e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | from langchain.tools import BaseTool
from langchain_community.utilities import WikipediaAPIWrapper
from pydantic import PrivateAttr
class WikiSearchTool(BaseTool):
"""
Инструмент для поиска в English Wikipedia.
"""
name: str = "wiki_search"
description: str = "Search English Wikipedia articles by keyword/title and return summaries. Use for biographical details, dates, Featured Article look-ups, discographies, or any question answerable from an encyclopedia entry."
_wrapper: WikipediaAPIWrapper = PrivateAttr()
def __init__(self) -> None:
super().__init__()
self._wrapper = WikipediaAPIWrapper(lang="en")
def _run(self, query: str) -> str:
return self._wrapper.run(query)
async def _arun(self, query: str) -> str:
raise NotImplementedError("Async not supported.")
|