mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-27 17:08:47 +00:00
community[patch]: Update TavilySearch to use TavilyClient instead of the deprecated Client (#24270)
On using TavilySearchAPIRetriever with any conversation chain getting error : `TypeError: Client.__init__() got an unexpected keyword argument 'api_key'` It is because the retreiver class is using the depreciated `Client` class, `TavilyClient` need to be used instead. --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com> Co-authored-by: Eugene Yurtsev <eugene@langchain.dev>
This commit is contained in:
parent
5f2dea2b20
commit
f5a38772a8
@ -31,14 +31,18 @@ class TavilySearchAPIRetriever(BaseRetriever):
|
|||||||
self, query: str, *, run_manager: CallbackManagerForRetrieverRun
|
self, query: str, *, run_manager: CallbackManagerForRetrieverRun
|
||||||
) -> List[Document]:
|
) -> List[Document]:
|
||||||
try:
|
try:
|
||||||
from tavily import Client
|
try:
|
||||||
|
from tavily import TavilyClient
|
||||||
|
except ImportError:
|
||||||
|
# Older of tavily used Client
|
||||||
|
from tavily import Client as TavilyClient
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Tavily python package not found. "
|
"Tavily python package not found. "
|
||||||
"Please install it with `pip install tavily-python`."
|
"Please install it with `pip install tavily-python`."
|
||||||
)
|
)
|
||||||
|
|
||||||
tavily = Client(api_key=self.api_key or os.environ["TAVILY_API_KEY"])
|
tavily = TavilyClient(api_key=self.api_key or os.environ["TAVILY_API_KEY"])
|
||||||
max_results = self.k if not self.include_generated_answer else self.k - 1
|
max_results = self.k if not self.include_generated_answer else self.k - 1
|
||||||
response = tavily.search(
|
response = tavily.search(
|
||||||
query=query,
|
query=query,
|
||||||
|
Loading…
Reference in New Issue
Block a user