diff --git a/libs/community/langchain_community/retrievers/tavily_search_api.py b/libs/community/langchain_community/retrievers/tavily_search_api.py index 317b5774ed0..a23d654a73c 100644 --- a/libs/community/langchain_community/retrievers/tavily_search_api.py +++ b/libs/community/langchain_community/retrievers/tavily_search_api.py @@ -31,14 +31,18 @@ class TavilySearchAPIRetriever(BaseRetriever): self, query: str, *, run_manager: CallbackManagerForRetrieverRun ) -> List[Document]: 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: raise ImportError( "Tavily python package not found. " "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 response = tavily.search( query=query,