tavily-ai / tavily-python

A python wrapper for Tavily search API
https://docs.tavily.com
MIT License
112 stars 21 forks source link

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

Closed rawwerks closed 7 months ago

rawwerks commented 7 months ago

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

assafelovic commented 7 months ago

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

assafelovic commented 7 months ago

Thanks for raising this we'll add the fix!