mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-15 07:36:08 +00:00
Harrison/searchapi (#14252)
Co-authored-by: SebastjanPrachovskij <86522260+SebastjanPrachovskij@users.noreply.github.com>
This commit is contained in:
parent
224aa5151d
commit
921c4b5597
@ -393,14 +393,24 @@ from langchain.chat_loaders.gmail import GMailLoader
|
||||
|
||||
## 3rd Party Integrations
|
||||
|
||||
### SearchApi
|
||||
|
||||
>[SearchApi](https://www.searchapi.io/) provides a 3rd-party API to access Google search results, YouTube search & transcripts, and other Google-related engines.
|
||||
|
||||
See [usage examples and authorization instructions](/docs/integrations/tools/searchapi).
|
||||
|
||||
```python
|
||||
from langchain.utilities import SearchApiAPIWrapper
|
||||
```
|
||||
|
||||
### SerpAPI
|
||||
|
||||
>[SerpApi](https://serpapi.com/) provides a 3rd-party API to access Google search results.
|
||||
|
||||
See a [usage example and authorization instructions](/docs/integrations/tools/google_serper).
|
||||
See a [usage example and authorization instructions](/docs/integrations/tools/serpapi).
|
||||
|
||||
```python
|
||||
from langchain.utilities import GoogleSerperAPIWrapper
|
||||
from langchain.utilities import SerpAPIWrapper
|
||||
```
|
||||
|
||||
### YouTube
|
||||
|
@ -9,7 +9,7 @@
|
||||
"\n",
|
||||
"LangChain provides async support for Agents by leveraging the [asyncio](https://docs.python.org/3/library/asyncio.html) library.\n",
|
||||
"\n",
|
||||
"Async methods are currently supported for the following `Tool`s: [`GoogleSerperAPIWrapper`](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/utilities/google_serper.py), [`SerpAPIWrapper`](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/utilities/serpapi.py), [`LLMMathChain`](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/chains/llm_math/base.py) and [`Qdrant`](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/vectorstores/qdrant.py). Async support for other agent tools are on the roadmap.\n",
|
||||
"Async methods are currently supported for the following `Tool`s: [`SearchApiAPIWrapper`](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/utilities/searchapi.py), [`GoogleSerperAPIWrapper`](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/utilities/google_serper.py), [`SerpAPIWrapper`](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/utilities/serpapi.py), [`LLMMathChain`](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/chains/llm_math/base.py) and [`Qdrant`](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/vectorstores/qdrant.py). Async support for other agent tools are on the roadmap.\n",
|
||||
"\n",
|
||||
"For `Tool`s that have a `coroutine` implemented (the four mentioned above), the `AgentExecutor` will `await` them directly. Otherwise, the `AgentExecutor` will call the `Tool`'s `func` via `asyncio.get_event_loop().run_in_executor` to avoid blocking the main runloop.\n",
|
||||
"\n",
|
||||
|
@ -13,6 +13,7 @@ from langchain.agents.tools import Tool
|
||||
from langchain.agents.utils import validate_tools_single_input
|
||||
from langchain.tools.base import BaseTool
|
||||
from langchain.utilities.google_serper import GoogleSerperAPIWrapper
|
||||
from langchain.utilities.searchapi import SearchApiAPIWrapper
|
||||
from langchain.utilities.serpapi import SerpAPIWrapper
|
||||
|
||||
|
||||
@ -64,7 +65,9 @@ class SelfAskWithSearchChain(AgentExecutor):
|
||||
def __init__(
|
||||
self,
|
||||
llm: BaseLanguageModel,
|
||||
search_chain: Union[GoogleSerperAPIWrapper, SerpAPIWrapper],
|
||||
search_chain: Union[
|
||||
GoogleSerperAPIWrapper, SearchApiAPIWrapper, SerpAPIWrapper
|
||||
],
|
||||
**kwargs: Any,
|
||||
):
|
||||
"""Initialize only with an LLM and a search chain."""
|
||||
|
@ -284,6 +284,18 @@ def _import_google_serper_tool_GoogleSerperRun() -> Any:
|
||||
return GoogleSerperRun
|
||||
|
||||
|
||||
def _import_searchapi_tool_SearchAPIResults() -> Any:
|
||||
from langchain.tools.searchapi.tool import SearchAPIResults
|
||||
|
||||
return SearchAPIResults
|
||||
|
||||
|
||||
def _import_searchapi_tool_SearchAPIRun() -> Any:
|
||||
from langchain.tools.searchapi.tool import SearchAPIRun
|
||||
|
||||
return SearchAPIRun
|
||||
|
||||
|
||||
def _import_graphql_tool() -> Any:
|
||||
from langchain.tools.graphql.tool import BaseGraphQLTool
|
||||
|
||||
@ -819,6 +831,10 @@ def __getattr__(name: str) -> Any:
|
||||
return _import_google_serper_tool_GoogleSerperResults()
|
||||
elif name == "GoogleSerperRun":
|
||||
return _import_google_serper_tool_GoogleSerperRun()
|
||||
elif name == "SearchAPIResults":
|
||||
return _import_searchapi_tool_SearchAPIResults()
|
||||
elif name == "SearchAPIRun":
|
||||
return _import_searchapi_tool_SearchAPIRun()
|
||||
elif name == "BaseGraphQLTool":
|
||||
return _import_graphql_tool()
|
||||
elif name == "HumanInputRun":
|
||||
@ -1023,6 +1039,8 @@ __all__ = [
|
||||
"GoogleSearchRun",
|
||||
"GoogleSerperResults",
|
||||
"GoogleSerperRun",
|
||||
"SearchAPIResults",
|
||||
"SearchAPIRun",
|
||||
"HumanInputRun",
|
||||
"IFTTTWebhook",
|
||||
"InfoPowerBITool",
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Integration test for self ask with search."""
|
||||
from langchain.agents.self_ask_with_search.base import SelfAskWithSearchChain
|
||||
from langchain.llms.openai import OpenAI
|
||||
from langchain.utilities.google_serper import GoogleSerperAPIWrapper
|
||||
from langchain.utilities.searchapi import SearchApiAPIWrapper
|
||||
|
||||
|
||||
def test_self_ask_with_search() -> None:
|
||||
@ -9,10 +9,10 @@ def test_self_ask_with_search() -> None:
|
||||
question = "What is the hometown of the reigning men's U.S. Open champion?"
|
||||
chain = SelfAskWithSearchChain(
|
||||
llm=OpenAI(temperature=0),
|
||||
search_chain=GoogleSerperAPIWrapper(),
|
||||
search_chain=SearchApiAPIWrapper(),
|
||||
input_key="q",
|
||||
output_key="a",
|
||||
)
|
||||
answer = chain.run(question)
|
||||
final_answer = answer.split("\n")[-1]
|
||||
assert final_answer == "El Palmar, Spain"
|
||||
assert final_answer == "Belgrade, Serbia"
|
||||
|
@ -104,5 +104,8 @@ def test_imports() -> None:
|
||||
from langchain.llms import OpenAI # noqa: F401
|
||||
from langchain.retrievers import VespaRetriever # noqa: F401
|
||||
from langchain.tools import DuckDuckGoSearchResults # noqa: F401
|
||||
from langchain.utilities import SerpAPIWrapper # noqa: F401
|
||||
from langchain.utilities import (
|
||||
SearchApiAPIWrapper, # noqa: F401
|
||||
SerpAPIWrapper, # noqa: F401
|
||||
)
|
||||
from langchain.vectorstores import FAISS # noqa: F401
|
||||
|
@ -92,6 +92,8 @@ EXPECTED_ALL = [
|
||||
"RequestsPostTool",
|
||||
"RequestsPutTool",
|
||||
"SceneXplainTool",
|
||||
"SearchAPIRun",
|
||||
"SearchAPIResults",
|
||||
"SearxSearchResults",
|
||||
"SearxSearchRun",
|
||||
"ShellTool",
|
||||
|
@ -94,6 +94,8 @@ _EXPECTED = [
|
||||
"RequestsPostTool",
|
||||
"RequestsPutTool",
|
||||
"SceneXplainTool",
|
||||
"SearchAPIResults",
|
||||
"SearchAPIRun",
|
||||
"SearxSearchResults",
|
||||
"SearxSearchRun",
|
||||
"ShellTool",
|
||||
|
Loading…
Reference in New Issue
Block a user