mirror of
https://github.com/hwchase17/langchain
synced 2024-11-02 09:40:22 +00:00
b051bba1a9
- **Description:** finishes adding the you.com functionality including: - add async functions to utility and retriever - add the You.com Tool - add async testing for utility, retriever, and tool - add a tool integration notebook page - **Dependencies:** any dependencies required for this change - **Twitter handle:** @scottnath
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from typing import Any, List
|
|
|
|
from langchain_core.callbacks import (
|
|
AsyncCallbackManagerForRetrieverRun,
|
|
CallbackManagerForRetrieverRun,
|
|
)
|
|
from langchain_core.documents import Document
|
|
from langchain_core.retrievers import BaseRetriever
|
|
|
|
from langchain_community.utilities import YouSearchAPIWrapper
|
|
|
|
|
|
class YouRetriever(BaseRetriever, YouSearchAPIWrapper):
|
|
"""`You` retriever that uses You.com's search API.
|
|
It wraps results() to get_relevant_documents
|
|
It uses all YouSearchAPIWrapper arguments without any change.
|
|
"""
|
|
|
|
def _get_relevant_documents(
|
|
self,
|
|
query: str,
|
|
*,
|
|
run_manager: CallbackManagerForRetrieverRun,
|
|
**kwargs: Any,
|
|
) -> List[Document]:
|
|
return self.results(query, run_manager=run_manager.get_child(), **kwargs)
|
|
|
|
async def _aget_relevant_documents(
|
|
self,
|
|
query: str,
|
|
*,
|
|
run_manager: AsyncCallbackManagerForRetrieverRun,
|
|
**kwargs: Any,
|
|
) -> List[Document]:
|
|
results = await self.results_async(
|
|
query, run_manager=run_manager.get_child(), **kwargs
|
|
)
|
|
return results
|