Cannot from tavily import TavilyClient

I tried the simple example here: Getting Started with Tavily Search

My first “pre-” problem is that there is a syntax error on the example page. print (result) should be print (response). But that was simple (although telling)…

My first problem was that it couldn’t import because I didn’t have the cohere library. So I did a pip install cohere. Am I going to need a cohere api key as well?

Now my problem is that I don’t have pymongo.

I give up!!! Where does this end? :rage: :weary:

Here is my code:

import os
from tavily import TavilyClient
from dotenv import load_dotenv
load_dotenv()

api_key = os.environ["TAVILY_API_KEY"]

# Step 1. Instantiating your TavilyClient
tavily_client = TavilyClient(api_key=api_key)

# Step 2. Executing a simple search query
response = tavily_client.search("Who is Leo Messi?")

# Step 3. That's it! You've done a Tavily Search!
# print(result) # <-- Incorrect on the web site
print(response)

Here is the current error:

Traceback (most recent call last):
  File "c:\Users\steph\source\my-ai-lessons\my-lesson01-tavily-search.py", line 2, in <module>
    from tavily import TavilyClient
  File "C:\Users\steph\.virtualenvs\my-ai-lessons-qzQ9fUMP\Lib\site-packages\tavily\__init__.py", line 4, in <module>
    from .hybrid_rag import TavilyHybridClient
  File "C:\Users\steph\.virtualenvs\my-ai-lessons-qzQ9fUMP\Lib\site-packages\tavily\hybrid_rag\__init__.py", line 1, in <module>
    from .hybrid_rag import TavilyHybridClient
  File "C:\Users\steph\.virtualenvs\my-ai-lessons-qzQ9fUMP\Lib\site-packages\tavily\hybrid_rag\hybrid_rag.py", line 5, in <module>
    from pymongo.collection import Collection
ModuleNotFoundError: No module named 'pymongo'

Hello,

We recently published an update to the Python client that introduced support for Hybrid RAG with MongoDB. That update accidentally introduced hard dependencies on cohere and pymongo. :cold_face: (oops)

This has now been fixed. Please update the package by running the following command:

pip install --upgrade tavily-python

We apologize for the inconvenience. :pray:

Thank you for pointing out the typo in our documentation, I’ll make sure it gets fixed asap!!

Best,
Carl

That worked. Thank you :heart: