mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-03 03:59:42 +00:00
community: Add you.com tool, add async to retriever, add async testing, add You tool doc (#18032)
- **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
This commit is contained in:
43
libs/community/langchain_community/tools/you/tool.py
Normal file
43
libs/community/langchain_community/tools/you/tool.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from typing import List, Optional, Type
|
||||
|
||||
from langchain_core.callbacks import (
|
||||
AsyncCallbackManagerForToolRun,
|
||||
CallbackManagerForToolRun,
|
||||
)
|
||||
from langchain_core.documents import Document
|
||||
from langchain_core.pydantic_v1 import BaseModel, Field
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
from langchain_community.utilities.you import YouSearchAPIWrapper
|
||||
|
||||
|
||||
class YouInput(BaseModel):
|
||||
query: str = Field(description="should be a search query")
|
||||
|
||||
|
||||
class YouSearchTool(BaseTool):
|
||||
"""Tool that searches the you.com API"""
|
||||
|
||||
name = "you_search"
|
||||
description = (
|
||||
"The YOU APIs make LLMs and search experiences more factual and"
|
||||
"up to date with realtime web data."
|
||||
)
|
||||
args_schema: Type[BaseModel] = YouInput
|
||||
api_wrapper: YouSearchAPIWrapper = Field(default_factory=YouSearchAPIWrapper)
|
||||
|
||||
def _run(
|
||||
self,
|
||||
query: str,
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> List[Document]:
|
||||
"""Use the you.com tool."""
|
||||
return self.api_wrapper.results(query)
|
||||
|
||||
async def _arun(
|
||||
self,
|
||||
query: str,
|
||||
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
|
||||
) -> List[Document]:
|
||||
"""Use the you.com tool asynchronously."""
|
||||
return await self.api_wrapper.results_async(query)
|
Reference in New Issue
Block a user