tavily-python 0.3.8__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. {tavily_python-0.3.8 → tavily_python-0.4.0}/LICENSE +21 -21
  2. {tavily_python-0.3.8/tavily_python.egg-info → tavily_python-0.4.0}/PKG-INFO +228 -226
  3. {tavily_python-0.3.8 → tavily_python-0.4.0}/README.md +211 -209
  4. {tavily_python-0.3.8 → tavily_python-0.4.0}/setup.cfg +8 -8
  5. {tavily_python-0.3.8 → tavily_python-0.4.0}/setup.py +23 -23
  6. {tavily_python-0.3.8 → tavily_python-0.4.0}/tavily/__init__.py +3 -3
  7. {tavily_python-0.3.8 → tavily_python-0.4.0}/tavily/async_tavily.py +206 -200
  8. {tavily_python-0.3.8 → tavily_python-0.4.0}/tavily/config.py +1 -1
  9. {tavily_python-0.3.8 → tavily_python-0.4.0}/tavily/errors.py +10 -10
  10. {tavily_python-0.3.8 → tavily_python-0.4.0}/tavily/hybrid_rag/hybrid_rag.py +204 -205
  11. {tavily_python-0.3.8 → tavily_python-0.4.0}/tavily/tavily.py +225 -219
  12. {tavily_python-0.3.8 → tavily_python-0.4.0}/tavily/utils.py +40 -40
  13. {tavily_python-0.3.8 → tavily_python-0.4.0/tavily_python.egg-info}/PKG-INFO +228 -226
  14. {tavily_python-0.3.8 → tavily_python-0.4.0}/tavily/hybrid_rag/__init__.py +0 -0
  15. {tavily_python-0.3.8 → tavily_python-0.4.0}/tavily_python.egg-info/SOURCES.txt +0 -0
  16. {tavily_python-0.3.8 → tavily_python-0.4.0}/tavily_python.egg-info/dependency_links.txt +0 -0
  17. {tavily_python-0.3.8 → tavily_python-0.4.0}/tavily_python.egg-info/requires.txt +0 -0
  18. {tavily_python-0.3.8 → tavily_python-0.4.0}/tavily_python.egg-info/top_level.txt +0 -0
  19. {tavily_python-0.3.8 → tavily_python-0.4.0}/tests/test_async_search.py +0 -0
  20. {tavily_python-0.3.8 → tavily_python-0.4.0}/tests/test_sync_search.py +0 -0
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Alpha AI Technologies Inc.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Alpha AI Technologies Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,226 +1,228 @@
1
- Metadata-Version: 2.1
2
- Name: tavily-python
3
- Version: 0.3.8
4
- Summary: Python wrapper for the Tavily API
5
- Home-page: https://github.com/tavily-ai/tavily-python
6
- Author: Tavily AI
7
- Author-email: support@tavily.com
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.6
12
- Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
- Requires-Dist: requests
15
- Requires-Dist: tiktoken>=0.5.1
16
- Requires-Dist: httpx
17
-
18
-
19
- # Tavily Python Wrapper
20
- The Tavily Python wrapper allows for easy interaction with the Tavily API, offering the full range of our search functionality directly from your Python programs. Easily integrate smart search capabilities into your applications, harnessing Tavily's powerful search features.
21
-
22
- ## Installing
23
-
24
- ```bash
25
- pip install tavily-python
26
- ```
27
-
28
- ## Usage
29
- Below are some code snippets that show you how to interact with our API. The different steps and components of this code are explained in more detail in the API Methods section further down.
30
-
31
- ### Getting and printing the full Search API response
32
-
33
- ```python
34
- from tavily import TavilyClient
35
-
36
- # Step 1. Instantiating your TavilyClient
37
- tavily_client = TavilyClient(api_key="tvly-YOUR_API_KEY")
38
-
39
- # Step 2. Executing a simple search query
40
- response = tavily_client.search("Who is Leo Messi?")
41
-
42
- # Step 3. That's it! You've done a Tavily Search!
43
- print(result)
44
- ```
45
- This is equivalent to directly querying our REST API.
46
-
47
- ### Generating context for a RAG Application
48
-
49
- ```python
50
- from tavily import TavilyClient
51
-
52
- # Step 1. Instantiating your TavilyClient
53
- tavily_client = TavilyClient(api_key="tvly-YOUR_API_KEY")
54
-
55
- # Step 2. Executing a context search query
56
- context = tavily_client.get_search_context(query="What happened during the Burning Man floods?")
57
-
58
- # Step 3. That's it! You now have a context string that you can feed directly into your RAG Application
59
- print(context)
60
- ```
61
- This is how you can generate precise and fact-based context for your RAG application in one line of code.
62
-
63
- ### Getting a quick answer to a question
64
-
65
- ```python
66
- from tavily import TavilyClient
67
-
68
- # Step 1. Instantiating your TavilyClient
69
- tavily_client = TavilyClient(api_key="tvly-YOUR_API_KEY")
70
-
71
- # Step 2. Executing a Q&A search query
72
- answer = tavily_client.qna_search(query="Who is Leo Messi?")
73
-
74
- # Step 3. That's it! Your question has been answered!
75
- print(answer)
76
- ```
77
- This is how you get accurate and concise answers to questions, in one line of code. Perfect for usage by LLMs!
78
-
79
- ## API Methods
80
-
81
- ### Client
82
-
83
- > **NEW!** We have released a Beta of our asynchronous Tavily client. It is available in version `0.3.4` of our Python package. The asynchronous client's interface is identical to the synchronous client's, the only difference being that all methods are asynchronous. Try it now with the `AsyncTavilyClient` class!
84
-
85
- The `TavilyClient` class is the entry point to interacting with the Tavily API. Kickstart your journey by instantiating it with your API key. If you want to use Tavily asynchronously, you will need to instantiate an `AsyncTavilyClient` instead.
86
-
87
- Once you do so, you're ready to search the Web in one line of code! All you need is to pass a `str` as a `query` to one of our methods (detailed below) and you'll start searching!
88
-
89
- ### Methods
90
- * **`search`**(query, **kwargs)
91
- * Performs a Tavily Search query and returns the response as a well-structured `dict`.
92
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`, `include_answer`, `include_raw_content`, `include_images`.
93
- * **Returns** a `dict` with all related response fields. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `dict`. The details of the exact response format are given in the Search Responses section further down.
94
-
95
- * **`get_search_context`**(query, **kwargs)
96
- * Performs a Tavily Search query and returns a `str` of content and sources within the provided token limit. It's useful for getting only related content from retrieved websites without having to deal with context extraction and token management.
97
- * The **core parameter** for this function is `max_tokens`, an `int`. It defaults to `4000`. It is provided as a keyword argument.
98
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`.
99
- * **Returns** a `str` containing the content and sources of the results. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
100
-
101
- * **`qna_search`**(query, **kwargs)
102
- * Performs a search and returns a string containing an answer to the original query. This is optimal to be used as a tool for AI agents.
103
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth` (defaults to `"advanced"`), `topic`, `max_results`, `include_domains`, `exclude_domains`.
104
- * **Returns** a `str` containing a short answer to the search query. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
105
-
106
- ### Keyword Arguments (optional)
107
-
108
- * **`search_depth`: str** - The depth of the search. It can be `"basic"` or `"advanced"`. Default is `"basic"` unless specified otherwise in a given method.
109
-
110
- * **`topic`: str** - The category of the search. This will determine which of our agents will be used for the search. Currently, only `"general"` and `"news"` are supported. Default is `"general"`.
111
-
112
- * **`max_results`: int** - The maximum number of search results to return. Default is `5`.
113
-
114
- * **`include_images`: bool** - Include a list of query-related images in the response. Default is `False`.
115
-
116
- * **`include_answer`: bool** - Include a short answer to original query. Default is `False`.
117
-
118
- * **`include_raw_content`: bool** - Include the cleaned and parsed HTML content of each search result. Default is `False`.
119
-
120
- * **`include_domains`: list[str]** - A list of domains to specifically include in the search results. Default is `None`, which includes all domains. Please note that this feature is only available when using the `"general"` search `topic`.
121
-
122
- * **`exclude_domains`: list[str]** - A list of domains to specifically exclude from the search results. Default is `None`, which doesn't exclude any domains. Please note that this feature is only available when using the `"general"` search `topic`.
123
-
124
- ### Search Responses
125
-
126
- * **`answer`: str**- The answer to your search query. This will be `None` unless `include_answer` is set to `True`.
127
-
128
- * **`query`: str** - Your search query.
129
-
130
- * **`response_time`: float** - Your search result response time.
131
-
132
- * **`images`: list[str]** - A list of query-related image URLs.
133
-
134
- * **`results`: list** - A list of sorted search results ranked by relevancy. Each result is in the following format:
135
- - **`title`: str** - The title of the search result URL.
136
- - **`url`: str** - The URL of the search result.
137
- - **`content`: str** - The most query related content from the scraped URL. We use proprietary AI and algorithms to extract only the most relevant content from each URL, to optimize for context quality and size.
138
- - **`raw_content`: str** - The parsed and cleaned HTML of the site. For now includes parsed text only. Please note that this will be `None` unless `include_raw_content` is set to `True`.
139
- - **`score`: float** - The relevance score of the search result.
140
- - **`published_date`: str (optional)** - The publication date of the source. This is only available if you are using `"news"` as your search `topic`.
141
-
142
-
143
- When you send a search query, the response `dict` you receive will be in the following format:
144
-
145
- ```python
146
- response = {
147
- "query" = "The query provided in the request",
148
- "answer" = "A short answer to the query", # This will be None if include_answer is set to False in the request
149
- "follow_up_questions": None, # This feature is still in development
150
- "images" = [
151
- "Image 1 URL",
152
- "Image 2 URL",
153
- "Image 3 URL",
154
- "Image 4 URL",
155
- "Image 5 URL"
156
- ], # This will be an empty list if include_images is not set to True
157
- "results" = [
158
- {
159
- "title": "Source 1 Title",
160
- "url": "Source 1 URL",
161
- "content": "Source 1 Content",
162
- "score": 0.99 # This is the "relevancy" score of the source. It ranges from 0 to 1.
163
- },
164
- {
165
- "title": "Source 2 Title",
166
- "url": "Source 2 URL",
167
- "content": "Source 2 Content",
168
- "score": 0.97
169
- },
170
- ] # This list will have max_results elements
171
- }
172
- ```
173
-
174
- ## Error Handling
175
-
176
- The Tavily Python SDK includes comprehensive error handling to ensure smooth interaction with the API. Below are the specific exceptions that might be raised during usage:
177
-
178
- 1. **Missing API Key**: If no API key is provided when initializing the `TavilyClient`, a `tavily.MissingAPIKeyError` will be raised. Ensure you pass a valid API key to the `TavilyClient` during instantiation.
179
-
180
- ```python
181
- from tavily import TavilyClient, MissingAPIKeyError
182
-
183
- try:
184
- tavily_client = TavilyClient(api_key="")
185
- except MissingAPIKeyError:
186
- print("API key is missing. Please provide a valid API key.")
187
- ```
188
-
189
- 2. **Invalid API Key**: If the API key provided is invalid, a `tavily.InvalidAPIKeyError` will be raised when sending a search query. Double-check that your API key is correct and active.
190
-
191
- ```python
192
- from tavily import TavilyClient, InvalidAPIKeyError
193
-
194
- tavily_client = TavilyClient(api_key="invalid-api-key")
195
-
196
- try:
197
- response = tavily_client.search("Who is Leo Messi?")
198
- except InvalidAPIKeyError:
199
- print("Invalid API key provided. Please check your API key.")
200
- ```
201
-
202
- 3. **Usage Limit Exceeded**: If the API key provided is valid but the request fails due to exceeding the rate limit, surpassing the plan's monthly limit, or hitting the key's pre-set monthly limit, a `tavily.UsageLimitExceededError` will be raised. Consider upgrading your plan or checking your usage limits.
203
-
204
- ```python
205
- from tavily import TavilyClient, UsageLimitExceededError
206
-
207
- tavily_client = TavilyClient(api_key="valid-api-key")
208
-
209
- try:
210
- response = tavily_client.search("Who is Leo Messi?")
211
- except UsageLimitExceededError:
212
- print("Usage limit exceeded. Please check your plan's usage limits or consider upgrading.")
213
- ```
214
-
215
- These errors ensure that you are aware of the specific issues related to your API key usage, allowing you to take appropriate actions to resolve them.
216
-
217
- ## License
218
-
219
- This project is licensed under the terms of the MIT license.
220
-
221
- ## Contact
222
-
223
- If you are encountering issues while using Tavily, please email us at support@tavily.com. We'll be happy to help you.
224
-
225
- If you want to stay updated on the latest Tavily news and releases, head to our [Developer Community](https://community.tavily.com) to learn more!
226
-
1
+ Metadata-Version: 2.1
2
+ Name: tavily-python
3
+ Version: 0.4.0
4
+ Summary: Python wrapper for the Tavily API
5
+ Home-page: https://github.com/tavily-ai/tavily-python
6
+ Author: Tavily AI
7
+ Author-email: support@tavily.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests
15
+ Requires-Dist: tiktoken>=0.5.1
16
+ Requires-Dist: httpx
17
+
18
+
19
+ # Tavily Python Wrapper
20
+ The Tavily Python wrapper allows for easy interaction with the Tavily API, offering the full range of our search functionality directly from your Python programs. Easily integrate smart search capabilities into your applications, harnessing Tavily's powerful search features.
21
+
22
+ ## Installing
23
+
24
+ ```bash
25
+ pip install tavily-python
26
+ ```
27
+
28
+ ## Usage
29
+ Below are some code snippets that show you how to interact with our API. The different steps and components of this code are explained in more detail in the API Methods section further down.
30
+
31
+ ### Getting and printing the full Search API response
32
+
33
+ ```python
34
+ from tavily import TavilyClient
35
+
36
+ # Step 1. Instantiating your TavilyClient
37
+ tavily_client = TavilyClient(api_key="tvly-YOUR_API_KEY")
38
+
39
+ # Step 2. Executing a simple search query
40
+ response = tavily_client.search("Who is Leo Messi?")
41
+
42
+ # Step 3. That's it! You've done a Tavily Search!
43
+ print(response)
44
+ ```
45
+ This is equivalent to directly querying our REST API.
46
+
47
+ ### Generating context for a RAG Application
48
+
49
+ ```python
50
+ from tavily import TavilyClient
51
+
52
+ # Step 1. Instantiating your TavilyClient
53
+ tavily_client = TavilyClient(api_key="tvly-YOUR_API_KEY")
54
+
55
+ # Step 2. Executing a context search query
56
+ context = tavily_client.get_search_context(query="What happened during the Burning Man floods?")
57
+
58
+ # Step 3. That's it! You now have a context string that you can feed directly into your RAG Application
59
+ print(context)
60
+ ```
61
+ This is how you can generate precise and fact-based context for your RAG application in one line of code.
62
+
63
+ ### Getting a quick answer to a question
64
+
65
+ ```python
66
+ from tavily import TavilyClient
67
+
68
+ # Step 1. Instantiating your TavilyClient
69
+ tavily_client = TavilyClient(api_key="tvly-YOUR_API_KEY")
70
+
71
+ # Step 2. Executing a Q&A search query
72
+ answer = tavily_client.qna_search(query="Who is Leo Messi?")
73
+
74
+ # Step 3. That's it! Your question has been answered!
75
+ print(answer)
76
+ ```
77
+ This is how you get accurate and concise answers to questions, in one line of code. Perfect for usage by LLMs!
78
+
79
+ ## API Methods
80
+
81
+ ### Client
82
+
83
+ > **NEW!** We have released a Beta of our asynchronous Tavily client. It is available in version `0.3.4` of our Python package. The asynchronous client's interface is identical to the synchronous client's, the only difference being that all methods are asynchronous. Try it now with the `AsyncTavilyClient` class!
84
+
85
+ The `TavilyClient` class is the entry point to interacting with the Tavily API. Kickstart your journey by instantiating it with your API key. If you want to use Tavily asynchronously, you will need to instantiate an `AsyncTavilyClient` instead.
86
+
87
+ Once you do so, you're ready to search the Web in one line of code! All you need is to pass a `str` as a `query` to one of our methods (detailed below) and you'll start searching!
88
+
89
+ ### Methods
90
+ * **`search`**(query, **kwargs)
91
+ * Performs a Tavily Search query and returns the response as a well-structured `dict`.
92
+ * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `days`, `max_results`, `include_domains`, `exclude_domains`, `include_answer`, `include_raw_content`, `include_images`.
93
+ * **Returns** a `dict` with all related response fields. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `dict`. The details of the exact response format are given in the Search Responses section further down.
94
+
95
+ * **`get_search_context`**(query, **kwargs)
96
+ * Performs a Tavily Search query and returns a `str` of content and sources within the provided token limit. It's useful for getting only related content from retrieved websites without having to deal with context extraction and token management.
97
+ * The **core parameter** for this function is `max_tokens`, an `int`. It defaults to `4000`. It is provided as a keyword argument.
98
+ * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `days`, `max_results`, `include_domains`, `exclude_domains`.
99
+ * **Returns** a `str` containing the content and sources of the results. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
100
+
101
+ * **`qna_search`**(query, **kwargs)
102
+ * Performs a search and returns a string containing an answer to the original query. This is optimal to be used as a tool for AI agents.
103
+ * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth` (defaults to `"advanced"`), `topic`, `days`, `max_results`, `include_domains`, `exclude_domains`.
104
+ * **Returns** a `str` containing a short answer to the search query. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
105
+
106
+ ### Keyword Arguments (optional)
107
+
108
+ * **`search_depth`: str** - The depth of the search. It can be `"basic"` or `"advanced"`. Default is `"basic"` unless specified otherwise in a given method.
109
+
110
+ * **`topic`: str** - The category of the search. This will determine which of our agents will be used for the search. Currently, only `"general"` and `"news"` are supported. Default is `"general"`.
111
+
112
+ * **`days`: int (optional)** - The number of days back from the current date to include in the search results. This specifies the time frame of data to be retrieved. Please note that this feature is only available when using the `"news"` search `topic`. Default is `3`.
113
+
114
+ * **`max_results`: int** - The maximum number of search results to return. Default is `5`.
115
+
116
+ * **`include_images`: bool** - Include a list of query-related images in the response. Default is `False`.
117
+
118
+ * **`include_answer`: bool** - Include a short answer to original query. Default is `False`.
119
+
120
+ * **`include_raw_content`: bool** - Include the cleaned and parsed HTML content of each search result. Default is `False`.
121
+
122
+ * **`include_domains`: list[str]** - A list of domains to specifically include in the search results. Default is `None`, which includes all domains.
123
+
124
+ * **`exclude_domains`: list[str]** - A list of domains to specifically exclude from the search results. Default is `None`, which doesn't exclude any domains.
125
+
126
+ ### Search Responses
127
+
128
+ * **`answer`: str**- The answer to your search query. This will be `None` unless `include_answer` is set to `True`.
129
+
130
+ * **`query`: str** - Your search query.
131
+
132
+ * **`response_time`: float** - Your search result response time.
133
+
134
+ * **`images`: list[str]** - A list of query-related image URLs.
135
+
136
+ * **`results`: list** - A list of sorted search results ranked by relevancy. Each result is in the following format:
137
+ - **`title`: str** - The title of the search result URL.
138
+ - **`url`: str** - The URL of the search result.
139
+ - **`content`: str** - The most query related content from the scraped URL. We use proprietary AI and algorithms to extract only the most relevant content from each URL, to optimize for context quality and size.
140
+ - **`raw_content`: str** - The parsed and cleaned HTML of the site. For now includes parsed text only. Please note that this will be `None` unless `include_raw_content` is set to `True`.
141
+ - **`score`: float** - The relevance score of the search result.
142
+ - **`published_date`: str (optional)** - The publication date of the source. This is only available if you are using `"news"` as your search `topic`.
143
+
144
+
145
+ When you send a search query, the response `dict` you receive will be in the following format:
146
+
147
+ ```python
148
+ response = {
149
+ "query" = "The query provided in the request",
150
+ "answer" = "A short answer to the query", # This will be None if include_answer is set to False in the request
151
+ "follow_up_questions": None, # This feature is still in development
152
+ "images" = [
153
+ "Image 1 URL",
154
+ "Image 2 URL",
155
+ "Image 3 URL",
156
+ "Image 4 URL",
157
+ "Image 5 URL"
158
+ ], # This will be an empty list if include_images is not set to True
159
+ "results" = [
160
+ {
161
+ "title": "Source 1 Title",
162
+ "url": "Source 1 URL",
163
+ "content": "Source 1 Content",
164
+ "score": 0.99 # This is the "relevancy" score of the source. It ranges from 0 to 1.
165
+ },
166
+ {
167
+ "title": "Source 2 Title",
168
+ "url": "Source 2 URL",
169
+ "content": "Source 2 Content",
170
+ "score": 0.97
171
+ },
172
+ ] # This list will have max_results elements
173
+ }
174
+ ```
175
+
176
+ ## Error Handling
177
+
178
+ The Tavily Python SDK includes comprehensive error handling to ensure smooth interaction with the API. Below are the specific exceptions that might be raised during usage:
179
+
180
+ 1. **Missing API Key**: If no API key is provided when initializing the `TavilyClient`, a `tavily.MissingAPIKeyError` will be raised. Ensure you pass a valid API key to the `TavilyClient` during instantiation.
181
+
182
+ ```python
183
+ from tavily import TavilyClient, MissingAPIKeyError
184
+
185
+ try:
186
+ tavily_client = TavilyClient(api_key="")
187
+ except MissingAPIKeyError:
188
+ print("API key is missing. Please provide a valid API key.")
189
+ ```
190
+
191
+ 2. **Invalid API Key**: If the API key provided is invalid, a `tavily.InvalidAPIKeyError` will be raised when sending a search query. Double-check that your API key is correct and active.
192
+
193
+ ```python
194
+ from tavily import TavilyClient, InvalidAPIKeyError
195
+
196
+ tavily_client = TavilyClient(api_key="invalid-api-key")
197
+
198
+ try:
199
+ response = tavily_client.search("Who is Leo Messi?")
200
+ except InvalidAPIKeyError:
201
+ print("Invalid API key provided. Please check your API key.")
202
+ ```
203
+
204
+ 3. **Usage Limit Exceeded**: If the API key provided is valid but the request fails due to exceeding the rate limit, surpassing the plan's monthly limit, or hitting the key's pre-set monthly limit, a `tavily.UsageLimitExceededError` will be raised. Consider upgrading your plan or checking your usage limits.
205
+
206
+ ```python
207
+ from tavily import TavilyClient, UsageLimitExceededError
208
+
209
+ tavily_client = TavilyClient(api_key="valid-api-key")
210
+
211
+ try:
212
+ response = tavily_client.search("Who is Leo Messi?")
213
+ except UsageLimitExceededError:
214
+ print("Usage limit exceeded. Please check your plan's usage limits or consider upgrading.")
215
+ ```
216
+
217
+ These errors ensure that you are aware of the specific issues related to your API key usage, allowing you to take appropriate actions to resolve them.
218
+
219
+ ## License
220
+
221
+ This project is licensed under the terms of the MIT license.
222
+
223
+ ## Contact
224
+
225
+ If you are encountering issues while using Tavily, please email us at support@tavily.com. We'll be happy to help you.
226
+
227
+ If you want to stay updated on the latest Tavily news and releases, head to our [Developer Community](https://community.tavily.com) to learn more!
228
+