tavily-python 0.7.14__tar.gz → 0.7.16__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.
- {tavily_python-0.7.14 → tavily_python-0.7.16}/PKG-INFO +3 -3
- {tavily_python-0.7.14 → tavily_python-0.7.16}/README.md +2 -2
- {tavily_python-0.7.14 → tavily_python-0.7.16}/setup.py +1 -1
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily/async_tavily.py +31 -2
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily/errors.py +8 -3
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily/tavily.py +37 -3
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily/utils.py +0 -11
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily_python.egg-info/PKG-INFO +3 -3
- {tavily_python-0.7.14 → tavily_python-0.7.16}/LICENSE +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/setup.cfg +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily/__init__.py +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily/config.py +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily/hybrid_rag/__init__.py +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily/hybrid_rag/hybrid_rag.py +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily_python.egg-info/SOURCES.txt +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily_python.egg-info/dependency_links.txt +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily_python.egg-info/requires.txt +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tavily_python.egg-info/top_level.txt +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tests/test_crawl.py +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tests/test_errors.py +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tests/test_map.py +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tests/test_research.py +0 -0
- {tavily_python-0.7.14 → tavily_python-0.7.16}/tests/test_search.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tavily-python
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.16
|
|
4
4
|
Summary: Python wrapper for the Tavily API
|
|
5
5
|
Home-page: https://github.com/tavily-ai/tavily-python
|
|
6
6
|
Author: Tavily AI
|
|
@@ -136,7 +136,7 @@ for result in response["results"]:
|
|
|
136
136
|
# Note that URLs that could not be extracted will be stored in response["failed_results"]
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
-
# Tavily Crawl
|
|
139
|
+
# Tavily Crawl
|
|
140
140
|
|
|
141
141
|
Crawl lets you traverse a website's content starting from a base URL.
|
|
142
142
|
|
|
@@ -172,7 +172,7 @@ for result in response["results"]:
|
|
|
172
172
|
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
# Tavily Map
|
|
175
|
+
# Tavily Map
|
|
176
176
|
|
|
177
177
|
Map lets you discover and visualize the structure of a website starting from a base URL.
|
|
178
178
|
|
|
@@ -109,7 +109,7 @@ for result in response["results"]:
|
|
|
109
109
|
# Note that URLs that could not be extracted will be stored in response["failed_results"]
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
# Tavily Crawl
|
|
112
|
+
# Tavily Crawl
|
|
113
113
|
|
|
114
114
|
Crawl lets you traverse a website's content starting from a base URL.
|
|
115
115
|
|
|
@@ -145,7 +145,7 @@ for result in response["results"]:
|
|
|
145
145
|
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
-
# Tavily Map
|
|
148
|
+
# Tavily Map
|
|
149
149
|
|
|
150
150
|
Map lets you discover and visualize the structure of a website starting from a base URL.
|
|
151
151
|
|
|
@@ -17,7 +17,8 @@ class AsyncTavilyClient:
|
|
|
17
17
|
def __init__(self, api_key: Optional[str] = None,
|
|
18
18
|
company_info_tags: Sequence[str] = ("news", "general", "finance"),
|
|
19
19
|
proxies: Optional[dict[str, str]] = None,
|
|
20
|
-
api_base_url: Optional[str] = None
|
|
20
|
+
api_base_url: Optional[str] = None,
|
|
21
|
+
client_source: Optional[str] = None):
|
|
21
22
|
if api_key is None:
|
|
22
23
|
api_key = os.getenv("TAVILY_API_KEY")
|
|
23
24
|
|
|
@@ -44,7 +45,7 @@ class AsyncTavilyClient:
|
|
|
44
45
|
headers={
|
|
45
46
|
"Content-Type": "application/json",
|
|
46
47
|
"Authorization": f"Bearer {api_key}",
|
|
47
|
-
"X-Client-Source": "tavily-python"
|
|
48
|
+
"X-Client-Source": client_source or "tavily-python"
|
|
48
49
|
},
|
|
49
50
|
base_url=self._api_base_url,
|
|
50
51
|
mounts=proxy_mounts
|
|
@@ -70,6 +71,7 @@ class AsyncTavilyClient:
|
|
|
70
71
|
country: str = None,
|
|
71
72
|
auto_parameters: bool = None,
|
|
72
73
|
include_favicon: bool = None,
|
|
74
|
+
include_usage: bool = None,
|
|
73
75
|
**kwargs,
|
|
74
76
|
) -> dict:
|
|
75
77
|
"""
|
|
@@ -92,6 +94,7 @@ class AsyncTavilyClient:
|
|
|
92
94
|
"country": country,
|
|
93
95
|
"auto_parameters": auto_parameters,
|
|
94
96
|
"include_favicon": include_favicon,
|
|
97
|
+
"include_usage": include_usage,
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
data = {k: v for k, v in data.items() if v is not None}
|
|
@@ -145,6 +148,7 @@ class AsyncTavilyClient:
|
|
|
145
148
|
country: str = None,
|
|
146
149
|
auto_parameters: bool = None,
|
|
147
150
|
include_favicon: bool = None,
|
|
151
|
+
include_usage: bool = None,
|
|
148
152
|
**kwargs, # Accept custom arguments
|
|
149
153
|
) -> dict:
|
|
150
154
|
"""
|
|
@@ -168,6 +172,7 @@ class AsyncTavilyClient:
|
|
|
168
172
|
country=country,
|
|
169
173
|
auto_parameters=auto_parameters,
|
|
170
174
|
include_favicon=include_favicon,
|
|
175
|
+
include_usage=include_usage,
|
|
171
176
|
**kwargs,
|
|
172
177
|
)
|
|
173
178
|
|
|
@@ -185,6 +190,9 @@ class AsyncTavilyClient:
|
|
|
185
190
|
format: Literal["markdown", "text"] = None,
|
|
186
191
|
timeout: float = 30,
|
|
187
192
|
include_favicon: bool = None,
|
|
193
|
+
include_usage: bool = None,
|
|
194
|
+
query: str = None,
|
|
195
|
+
chunks_per_source: int = None,
|
|
188
196
|
**kwargs
|
|
189
197
|
) -> dict:
|
|
190
198
|
"""
|
|
@@ -198,6 +206,9 @@ class AsyncTavilyClient:
|
|
|
198
206
|
"format": format,
|
|
199
207
|
"timeout": timeout,
|
|
200
208
|
"include_favicon": include_favicon,
|
|
209
|
+
"include_usage": include_usage,
|
|
210
|
+
"query": query,
|
|
211
|
+
"chunks_per_source": chunks_per_source,
|
|
201
212
|
}
|
|
202
213
|
|
|
203
214
|
data = {k: v for k, v in data.items() if v is not None}
|
|
@@ -239,6 +250,9 @@ class AsyncTavilyClient:
|
|
|
239
250
|
format: Literal["markdown", "text"] = None,
|
|
240
251
|
timeout: float = 30,
|
|
241
252
|
include_favicon: bool = None,
|
|
253
|
+
include_usage: bool = None,
|
|
254
|
+
query: str = None,
|
|
255
|
+
chunks_per_source: int = None,
|
|
242
256
|
**kwargs, # Accept custom arguments
|
|
243
257
|
) -> dict:
|
|
244
258
|
"""
|
|
@@ -251,6 +265,9 @@ class AsyncTavilyClient:
|
|
|
251
265
|
format,
|
|
252
266
|
timeout,
|
|
253
267
|
include_favicon=include_favicon,
|
|
268
|
+
include_usage=include_usage,
|
|
269
|
+
query=query,
|
|
270
|
+
chunks_per_source=chunks_per_source,
|
|
254
271
|
**kwargs,
|
|
255
272
|
)
|
|
256
273
|
|
|
@@ -278,6 +295,8 @@ class AsyncTavilyClient:
|
|
|
278
295
|
format: Literal["markdown", "text"] = None,
|
|
279
296
|
timeout: float = 150,
|
|
280
297
|
include_favicon: bool = None,
|
|
298
|
+
include_usage: bool = None,
|
|
299
|
+
chunks_per_source: int = None,
|
|
281
300
|
**kwargs
|
|
282
301
|
) -> dict:
|
|
283
302
|
"""
|
|
@@ -299,6 +318,8 @@ class AsyncTavilyClient:
|
|
|
299
318
|
"format": format,
|
|
300
319
|
"timeout": timeout,
|
|
301
320
|
"include_favicon": include_favicon,
|
|
321
|
+
"include_usage": include_usage,
|
|
322
|
+
"chunks_per_source": chunks_per_source,
|
|
302
323
|
}
|
|
303
324
|
|
|
304
325
|
if kwargs:
|
|
@@ -348,6 +369,8 @@ class AsyncTavilyClient:
|
|
|
348
369
|
format: Literal["markdown", "text"] = None,
|
|
349
370
|
timeout: float = 150,
|
|
350
371
|
include_favicon: bool = None,
|
|
372
|
+
include_usage: bool = None,
|
|
373
|
+
chunks_per_source: int = None,
|
|
351
374
|
**kwargs
|
|
352
375
|
) -> dict:
|
|
353
376
|
"""
|
|
@@ -369,6 +392,8 @@ class AsyncTavilyClient:
|
|
|
369
392
|
format=format,
|
|
370
393
|
timeout=timeout,
|
|
371
394
|
include_favicon=include_favicon,
|
|
395
|
+
include_usage=include_usage,
|
|
396
|
+
chunks_per_source=chunks_per_source,
|
|
372
397
|
**kwargs)
|
|
373
398
|
|
|
374
399
|
return response_dict
|
|
@@ -386,6 +411,7 @@ class AsyncTavilyClient:
|
|
|
386
411
|
allow_external: bool = None,
|
|
387
412
|
include_images: bool = None,
|
|
388
413
|
timeout: float = 150,
|
|
414
|
+
include_usage: bool = None,
|
|
389
415
|
**kwargs
|
|
390
416
|
) -> dict:
|
|
391
417
|
"""
|
|
@@ -404,6 +430,7 @@ class AsyncTavilyClient:
|
|
|
404
430
|
"allow_external": allow_external,
|
|
405
431
|
"include_images": include_images,
|
|
406
432
|
"timeout": timeout,
|
|
433
|
+
"include_usage": include_usage,
|
|
407
434
|
}
|
|
408
435
|
|
|
409
436
|
if kwargs:
|
|
@@ -450,6 +477,7 @@ class AsyncTavilyClient:
|
|
|
450
477
|
allow_external: bool = None,
|
|
451
478
|
include_images: bool = None,
|
|
452
479
|
timeout: float = 150,
|
|
480
|
+
include_usage: bool = None,
|
|
453
481
|
**kwargs
|
|
454
482
|
) -> dict:
|
|
455
483
|
"""
|
|
@@ -468,6 +496,7 @@ class AsyncTavilyClient:
|
|
|
468
496
|
allow_external=allow_external,
|
|
469
497
|
include_images=include_images,
|
|
470
498
|
timeout=timeout,
|
|
499
|
+
include_usage=include_usage,
|
|
471
500
|
**kwargs)
|
|
472
501
|
|
|
473
502
|
return response_dict
|
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
from typing import List, Dict, Any, Optional
|
|
2
|
-
|
|
3
1
|
class UsageLimitExceededError(Exception):
|
|
4
2
|
def __init__(self, message: str):
|
|
5
3
|
super().__init__(message)
|
|
6
4
|
|
|
5
|
+
|
|
7
6
|
class BadRequestError(Exception):
|
|
8
7
|
def __init__(self, message: str):
|
|
9
8
|
super().__init__(message)
|
|
10
9
|
|
|
10
|
+
|
|
11
11
|
class ForbiddenError(Exception):
|
|
12
12
|
def __init__(self, message: str):
|
|
13
13
|
super().__init__(message)
|
|
14
14
|
|
|
15
|
+
|
|
15
16
|
class InvalidAPIKeyError(Exception):
|
|
16
17
|
def __init__(self, message: str):
|
|
17
18
|
super().__init__(message)
|
|
18
19
|
|
|
20
|
+
|
|
19
21
|
class TimeoutError(Exception):
|
|
20
22
|
def __init__(self, timeout: float):
|
|
21
23
|
super().__init__(f"Request timed out after {timeout} seconds.")
|
|
22
24
|
|
|
25
|
+
|
|
23
26
|
class MissingAPIKeyError(Exception):
|
|
24
27
|
def __init__(self):
|
|
25
|
-
super().__init__(
|
|
28
|
+
super().__init__(
|
|
29
|
+
"No API key provided. Please provide the api_key attribute or set the TAVILY_API_KEY environment variable."
|
|
30
|
+
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import requests
|
|
2
2
|
import json
|
|
3
|
-
import warnings
|
|
4
3
|
import os
|
|
4
|
+
import warnings
|
|
5
5
|
from typing import Literal, Sequence, Optional, List, Union, Generator
|
|
6
6
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
7
7
|
from .utils import get_max_items_from_list
|
|
@@ -12,7 +12,7 @@ class TavilyClient:
|
|
|
12
12
|
Tavily API client class.
|
|
13
13
|
"""
|
|
14
14
|
|
|
15
|
-
def __init__(self, api_key: Optional[str] = None, proxies: Optional[dict[str, str]] = None, api_base_url: Optional[str] = None):
|
|
15
|
+
def __init__(self, api_key: Optional[str] = None, proxies: Optional[dict[str, str]] = None, api_base_url: Optional[str] = None, client_source: Optional[str] = None):
|
|
16
16
|
if api_key is None:
|
|
17
17
|
api_key = os.getenv("TAVILY_API_KEY")
|
|
18
18
|
|
|
@@ -32,7 +32,7 @@ class TavilyClient:
|
|
|
32
32
|
self.headers = {
|
|
33
33
|
"Content-Type": "application/json",
|
|
34
34
|
"Authorization": f"Bearer {self.api_key}",
|
|
35
|
-
"X-Client-Source": "tavily-python"
|
|
35
|
+
"X-Client-Source": client_source or "tavily-python"
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
def _search(self,
|
|
@@ -53,6 +53,7 @@ class TavilyClient:
|
|
|
53
53
|
country: str = None,
|
|
54
54
|
auto_parameters: bool = None,
|
|
55
55
|
include_favicon: bool = None,
|
|
56
|
+
include_usage: bool = None,
|
|
56
57
|
**kwargs
|
|
57
58
|
) -> dict:
|
|
58
59
|
"""
|
|
@@ -76,6 +77,7 @@ class TavilyClient:
|
|
|
76
77
|
"country": country,
|
|
77
78
|
"auto_parameters": auto_parameters,
|
|
78
79
|
"include_favicon": include_favicon,
|
|
80
|
+
"include_usage": include_usage,
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
data = {k: v for k, v in data.items() if v is not None}
|
|
@@ -130,6 +132,7 @@ class TavilyClient:
|
|
|
130
132
|
country: str = None,
|
|
131
133
|
auto_parameters: bool = None,
|
|
132
134
|
include_favicon: bool = None,
|
|
135
|
+
include_usage: bool = None,
|
|
133
136
|
**kwargs, # Accept custom arguments
|
|
134
137
|
) -> dict:
|
|
135
138
|
"""
|
|
@@ -153,6 +156,7 @@ class TavilyClient:
|
|
|
153
156
|
country=country,
|
|
154
157
|
auto_parameters=auto_parameters,
|
|
155
158
|
include_favicon=include_favicon,
|
|
159
|
+
include_usage=include_usage,
|
|
156
160
|
**kwargs,
|
|
157
161
|
)
|
|
158
162
|
|
|
@@ -169,6 +173,9 @@ class TavilyClient:
|
|
|
169
173
|
format: Literal["markdown", "text"] = None,
|
|
170
174
|
timeout: float = 30,
|
|
171
175
|
include_favicon: bool = None,
|
|
176
|
+
include_usage: bool = None,
|
|
177
|
+
query: str = None,
|
|
178
|
+
chunks_per_source: int = None,
|
|
172
179
|
**kwargs
|
|
173
180
|
) -> dict:
|
|
174
181
|
"""
|
|
@@ -181,6 +188,9 @@ class TavilyClient:
|
|
|
181
188
|
"format": format,
|
|
182
189
|
"timeout": timeout,
|
|
183
190
|
"include_favicon": include_favicon,
|
|
191
|
+
"include_usage": include_usage,
|
|
192
|
+
"query": query,
|
|
193
|
+
"chunks_per_source": chunks_per_source,
|
|
184
194
|
}
|
|
185
195
|
|
|
186
196
|
data = {k: v for k, v in data.items() if v is not None}
|
|
@@ -220,6 +230,9 @@ class TavilyClient:
|
|
|
220
230
|
format: Literal["markdown", "text"] = None,
|
|
221
231
|
timeout: float = 30,
|
|
222
232
|
include_favicon: bool = None,
|
|
233
|
+
include_usage: bool = None,
|
|
234
|
+
query: str = None,
|
|
235
|
+
chunks_per_source: int = None,
|
|
223
236
|
**kwargs, # Accept custom arguments
|
|
224
237
|
) -> dict:
|
|
225
238
|
"""
|
|
@@ -231,6 +244,9 @@ class TavilyClient:
|
|
|
231
244
|
format,
|
|
232
245
|
timeout,
|
|
233
246
|
include_favicon=include_favicon,
|
|
247
|
+
include_usage=include_usage,
|
|
248
|
+
query=query,
|
|
249
|
+
chunks_per_source=chunks_per_source,
|
|
234
250
|
**kwargs)
|
|
235
251
|
|
|
236
252
|
tavily_results = response_dict.get("results", [])
|
|
@@ -257,6 +273,8 @@ class TavilyClient:
|
|
|
257
273
|
format: Literal["markdown", "text"] = None,
|
|
258
274
|
timeout: float = 150,
|
|
259
275
|
include_favicon: bool = None,
|
|
276
|
+
include_usage: bool = None,
|
|
277
|
+
chunks_per_source: int = None,
|
|
260
278
|
**kwargs
|
|
261
279
|
) -> dict:
|
|
262
280
|
"""
|
|
@@ -279,6 +297,8 @@ class TavilyClient:
|
|
|
279
297
|
"format": format,
|
|
280
298
|
"timeout": timeout,
|
|
281
299
|
"include_favicon": include_favicon,
|
|
300
|
+
"include_usage": include_usage,
|
|
301
|
+
"chunks_per_source": chunks_per_source,
|
|
282
302
|
}
|
|
283
303
|
|
|
284
304
|
if kwargs:
|
|
@@ -328,6 +348,8 @@ class TavilyClient:
|
|
|
328
348
|
format: Literal["markdown", "text"] = None,
|
|
329
349
|
timeout: float = 150,
|
|
330
350
|
include_favicon: bool = None,
|
|
351
|
+
include_usage: bool = None,
|
|
352
|
+
chunks_per_source: int = None,
|
|
331
353
|
**kwargs
|
|
332
354
|
) -> dict:
|
|
333
355
|
"""
|
|
@@ -349,6 +371,8 @@ class TavilyClient:
|
|
|
349
371
|
format=format,
|
|
350
372
|
timeout=timeout,
|
|
351
373
|
include_favicon=include_favicon,
|
|
374
|
+
include_usage=include_usage,
|
|
375
|
+
chunks_per_source=chunks_per_source,
|
|
352
376
|
**kwargs)
|
|
353
377
|
|
|
354
378
|
return response_dict
|
|
@@ -366,6 +390,7 @@ class TavilyClient:
|
|
|
366
390
|
allow_external: bool = None,
|
|
367
391
|
include_images: bool = None,
|
|
368
392
|
timeout: float = 150,
|
|
393
|
+
include_usage: bool = None,
|
|
369
394
|
**kwargs
|
|
370
395
|
) -> dict:
|
|
371
396
|
"""
|
|
@@ -384,6 +409,7 @@ class TavilyClient:
|
|
|
384
409
|
"allow_external": allow_external,
|
|
385
410
|
"include_images": include_images,
|
|
386
411
|
"timeout": timeout,
|
|
412
|
+
"include_usage": include_usage,
|
|
387
413
|
}
|
|
388
414
|
|
|
389
415
|
if kwargs:
|
|
@@ -430,6 +456,7 @@ class TavilyClient:
|
|
|
430
456
|
allow_external: bool = None,
|
|
431
457
|
include_images: bool = None,
|
|
432
458
|
timeout: float = 150,
|
|
459
|
+
include_usage: bool = None,
|
|
433
460
|
**kwargs
|
|
434
461
|
) -> dict:
|
|
435
462
|
"""
|
|
@@ -448,6 +475,7 @@ class TavilyClient:
|
|
|
448
475
|
allow_external=allow_external,
|
|
449
476
|
include_images=include_images,
|
|
450
477
|
timeout=timeout,
|
|
478
|
+
include_usage=include_usage,
|
|
451
479
|
**kwargs)
|
|
452
480
|
|
|
453
481
|
return response_dict
|
|
@@ -474,6 +502,8 @@ class TavilyClient:
|
|
|
474
502
|
|
|
475
503
|
Returns a string of JSON containing the search context up to context limit.
|
|
476
504
|
"""
|
|
505
|
+
warnings.warn("get_search_context is deprecated and will be removed in future versions.",
|
|
506
|
+
DeprecationWarning, stacklevel=2)
|
|
477
507
|
|
|
478
508
|
response_dict = self._search(query,
|
|
479
509
|
search_depth=search_depth,
|
|
@@ -511,6 +541,8 @@ class TavilyClient:
|
|
|
511
541
|
"""
|
|
512
542
|
Q&A search method. Search depth is advanced by default to get the best answer.
|
|
513
543
|
"""
|
|
544
|
+
warnings.warn("qna_search is deprecated and will be removed in future versions.",
|
|
545
|
+
DeprecationWarning, stacklevel=2)
|
|
514
546
|
response_dict = self._search(query,
|
|
515
547
|
search_depth=search_depth,
|
|
516
548
|
topic=topic,
|
|
@@ -537,6 +569,8 @@ class TavilyClient:
|
|
|
537
569
|
country: str = None,
|
|
538
570
|
) -> Sequence[dict]:
|
|
539
571
|
""" Company information search method. Search depth is advanced by default to get the best answer. """
|
|
572
|
+
warnings.warn("get_company_info is deprecated and will be removed in future versions.",
|
|
573
|
+
DeprecationWarning, stacklevel=2)
|
|
540
574
|
def _perform_search(topic):
|
|
541
575
|
return self._search(query,
|
|
542
576
|
search_depth=search_depth,
|
|
@@ -12,17 +12,6 @@ def get_total_tokens_from_string(string: str, encoding_name: str = DEFAULT_MODEL
|
|
|
12
12
|
tokens = encoding.encode(string)
|
|
13
13
|
return len(tokens)
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
def get_max_tokens_from_string(string: str, max_tokens: int, encoding_name: str = DEFAULT_MODEL_ENCODING) -> str:
|
|
17
|
-
"""
|
|
18
|
-
Extract max tokens from string using the specified encoding (based on openai compute)
|
|
19
|
-
"""
|
|
20
|
-
encoding = tiktoken.encoding_for_model(encoding_name)
|
|
21
|
-
tokens = encoding.encode(string)
|
|
22
|
-
token_bytes = [encoding.decode_single_token_bytes(token) for token in tokens[:max_tokens]]
|
|
23
|
-
return b"".join(token_bytes).decode()
|
|
24
|
-
|
|
25
|
-
|
|
26
15
|
def get_max_items_from_list(data: Sequence[dict], max_tokens: int = DEFAULT_MAX_TOKENS) -> List[Dict[str,str]]:
|
|
27
16
|
"""
|
|
28
17
|
Get max items from list of items based on defined max tokens (based on openai compute)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tavily-python
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.16
|
|
4
4
|
Summary: Python wrapper for the Tavily API
|
|
5
5
|
Home-page: https://github.com/tavily-ai/tavily-python
|
|
6
6
|
Author: Tavily AI
|
|
@@ -136,7 +136,7 @@ for result in response["results"]:
|
|
|
136
136
|
# Note that URLs that could not be extracted will be stored in response["failed_results"]
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
-
# Tavily Crawl
|
|
139
|
+
# Tavily Crawl
|
|
140
140
|
|
|
141
141
|
Crawl lets you traverse a website's content starting from a base URL.
|
|
142
142
|
|
|
@@ -172,7 +172,7 @@ for result in response["results"]:
|
|
|
172
172
|
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
# Tavily Map
|
|
175
|
+
# Tavily Map
|
|
176
176
|
|
|
177
177
|
Map lets you discover and visualize the structure of a website starting from a base URL.
|
|
178
178
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|