mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-16 06:53:16 +00:00
Harrison/searchapi (#14252)
Co-authored-by: SebastjanPrachovskij <86522260+SebastjanPrachovskij@users.noreply.github.com>
This commit is contained in:
@@ -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",
|
||||
|
Reference in New Issue
Block a user