tavily-ai/tavily-python

did the API structure change? python SDK example doesn't run

Closed this issue · 2 comments

Hi I am testing out the API via your demo code: https://docs.tavily.com/docs/tavily-api/python-sdk

i didn't make it very far:

!pip install tavily-python
from tavily import TavilyClient
tavily = TavilyClient(api_key="my key")
response = tavily.search(query="my query")
context = [{"url": obj["url"], "content": obj["content"]} for obj in response.results]

the API returns response, but the code to find the results is broken. my guess is that the output structure of the API was changed without updating the documentation, see the error:

----> [8](vscode-notebook-cell:/my/path/tavily-api-test.ipynb#W1sZmlsZQ%3D%3D?line=7) context = [{"url": obj["url"], "content": obj["content"]} for obj in response.results]

AttributeError: 'dict' object has no attribute 'results'

@assafelovic please advise

@rawwerks instead of response.results change it to response.get("results")

Thanks for raising this we'll add the fix!