Update app.py
Browse files
app.py
CHANGED
@@ -141,6 +141,73 @@ with gr.Blocks(title="Tavily Search API", theme=gr.themes.Soft()) as app:
|
|
141 |
gr.Markdown("# π Tavily Search API Interface")
|
142 |
gr.Markdown("Search the web using Tavily's powerful search API with customizable parameters.")
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
with gr.Row():
|
145 |
with gr.Column(scale=1):
|
146 |
# API Configuration
|
@@ -273,16 +340,186 @@ with gr.Blocks(title="Tavily Search API", theme=gr.themes.Soft()) as app:
|
|
273 |
)
|
274 |
|
275 |
# Examples
|
276 |
-
gr.Markdown("## π‘ Examples")
|
277 |
gr.Examples(
|
278 |
[
|
279 |
-
|
280 |
-
[
|
281 |
-
|
282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
],
|
284 |
-
|
285 |
-
label="Click on an example to load it"
|
286 |
)
|
287 |
|
288 |
# Connect the search button
|
|
|
141 |
gr.Markdown("# π Tavily Search API Interface")
|
142 |
gr.Markdown("Search the web using Tavily's powerful search API with customizable parameters.")
|
143 |
|
144 |
+
# Add documentation accordion
|
145 |
+
with gr.Accordion("π API Documentation & Parameter Options", open=False):
|
146 |
+
gr.Markdown("""
|
147 |
+
## Available Options
|
148 |
+
|
149 |
+
### **topic**: The category of the search
|
150 |
+
- **news**: Useful for retrieving real-time updates, particularly about politics, sports, and major current events covered by mainstream media sources
|
151 |
+
- **general**: For broader, more general-purpose searches that may include a wide range of sources
|
152 |
+
|
153 |
+
**Available options**: `general`, `news`
|
154 |
+
|
155 |
+
### **search_depth**: The depth of the search
|
156 |
+
- **advanced**: Tailored to retrieve the most relevant sources and content snippets for your query (costs 2 API Credits)
|
157 |
+
- **basic**: Provides generic content snippets from each source (costs 1 API Credit)
|
158 |
+
|
159 |
+
**Available options**: `basic`, `advanced`
|
160 |
+
|
161 |
+
### **chunks_per_source**: Content snippets control
|
162 |
+
Chunks are short content snippets (maximum 500 characters each) pulled directly from the source. Use this to define the maximum number of relevant chunks returned per source and to control the content length. Chunks will appear in the content field as: `<chunk 1> [...] <chunk 2> [...] <chunk 3>`.
|
163 |
+
|
164 |
+
**Note**: Available only when `search_depth` is `advanced`
|
165 |
+
|
166 |
+
**Required range**: 1 β€ x β€ 3
|
167 |
+
|
168 |
+
### **max_results**: Maximum number of search results
|
169 |
+
The maximum number of search results to return.
|
170 |
+
|
171 |
+
**Required range**: 0 β€ x β€ 20
|
172 |
+
|
173 |
+
### **time_range**: Time filtering
|
174 |
+
The time range back from the current date to filter results. Useful when looking for sources that have published data.
|
175 |
+
|
176 |
+
**Available options**: `day`, `week`, `month`, `year`, `d`, `w`, `m`, `y`
|
177 |
+
|
178 |
+
### **days**: Days back for news searches
|
179 |
+
Number of days back from the current date to include. Available only if topic is `news`.
|
180 |
+
|
181 |
+
**Required range**: x β₯ 1
|
182 |
+
|
183 |
+
### **include_answer**: LLM-generated answer
|
184 |
+
Include an LLM-generated answer to the provided query.
|
185 |
+
- `basic` or `true`: Returns a quick answer
|
186 |
+
- `advanced`: Returns a more detailed answer
|
187 |
+
|
188 |
+
### **include_raw_content**: Raw HTML content
|
189 |
+
Include the cleaned and parsed HTML content of each search result.
|
190 |
+
- `markdown` or `true`: Returns search result content in markdown format
|
191 |
+
- `text`: Returns the plain text from the results (may increase latency)
|
192 |
+
|
193 |
+
### **include_images**: Image search
|
194 |
+
Also perform an image search and include the results in the response.
|
195 |
+
|
196 |
+
### **include_image_descriptions**: Image descriptions
|
197 |
+
When `include_images` is true, also add a descriptive text for each image.
|
198 |
+
|
199 |
+
### **include_domains**: Domain inclusion
|
200 |
+
A list of domains to specifically include in the search results.
|
201 |
+
|
202 |
+
### **exclude_domains**: Domain exclusion
|
203 |
+
A list of domains to specifically exclude from the search results.
|
204 |
+
|
205 |
+
### **country**: Country-specific boosting
|
206 |
+
Boost search results from a specific country. This will prioritize content from the selected country in the search results. Available only if topic is `general`.
|
207 |
+
|
208 |
+
**Available countries**: afghanistan, albania, algeria, andorra, angola, argentina, armenia, australia, austria, azerbaijan, bahamas, bahrain, bangladesh, barbados, belarus, belgium, belize, benin, bhutan, bolivia, bosnia and herzegovina, botswana, brazil, brunei, bulgaria, burkina faso, burundi, cambodia, cameroon, canada, cape verde, central african republic, chad, chile, china, colombia, comoros, congo, costa rica, croatia, cuba, cyprus, czech republic, denmark, djibouti, dominican republic, ecuador, egypt, el salvador, equatorial guinea, eritrea, estonia, ethiopia, fiji, finland, france, gabon, gambia, georgia, germany, ghana, greece, guatemala, guinea, haiti, honduras, hungary, iceland, india, indonesia, iran, iraq, ireland, israel, italy, jamaica, japan, jordan, kazakhstan, kenya, kuwait, kyrgyzstan, latvia, lebanon, lesotho, liberia, libya, liechtenstein, lithuania, luxembourg, madagascar, malawi, malaysia, maldives, mali, malta, mauritania, mauritius, mexico, moldova, monaco, mongolia, montenegro, morocco, mozambique, myanmar, namibia, nepal, netherlands, new zealand, nicaragua, niger, nigeria, north korea, north macedonia, norway, oman, pakistan, panama, papua new guinea, paraguay, peru, philippines, poland, portugal, qatar, romania, russia, rwanda, saudi arabia, senegal, serbia, singapore, slovakia, slovenia, somalia, south africa, south korea, south sudan, spain, sri lanka, sudan, sweden, switzerland, syria, taiwan, tajikistan, tanzania, thailand, togo, trinidad and tobago, tunisia, turkey, turkmenistan, uganda, ukraine, united arab emirates, united kingdom, united states, uruguay, uzbekistan, venezuela, vietnam, yemen, zambia, zimbabwe
|
209 |
+
""")
|
210 |
+
|
211 |
with gr.Row():
|
212 |
with gr.Column(scale=1):
|
213 |
# API Configuration
|
|
|
340 |
)
|
341 |
|
342 |
# Examples
|
343 |
+
gr.Markdown("## π‘ Comprehensive Test Examples")
|
344 |
gr.Examples(
|
345 |
[
|
346 |
+
# Basic general search
|
347 |
+
[
|
348 |
+
"Who is Leo Messi?", # query
|
349 |
+
"general", # topic
|
350 |
+
"basic", # search_depth
|
351 |
+
3, # chunks_per_source
|
352 |
+
5, # max_results
|
353 |
+
"None", # time_range
|
354 |
+
7, # days
|
355 |
+
True, # include_answer
|
356 |
+
"false", # include_raw_content
|
357 |
+
False, # include_images
|
358 |
+
False, # include_image_descriptions
|
359 |
+
"", # include_domains
|
360 |
+
"", # exclude_domains
|
361 |
+
"None" # country
|
362 |
+
],
|
363 |
+
# Advanced news search with time filter
|
364 |
+
[
|
365 |
+
"Latest artificial intelligence breakthroughs",
|
366 |
+
"news",
|
367 |
+
"advanced",
|
368 |
+
3,
|
369 |
+
3,
|
370 |
+
"week",
|
371 |
+
3,
|
372 |
+
True,
|
373 |
+
"markdown",
|
374 |
+
False,
|
375 |
+
False,
|
376 |
+
"",
|
377 |
+
"",
|
378 |
+
"None"
|
379 |
+
],
|
380 |
+
# Python tutorials with domain inclusion
|
381 |
+
[
|
382 |
+
"Python machine learning tutorials",
|
383 |
+
"general",
|
384 |
+
"advanced",
|
385 |
+
2,
|
386 |
+
8,
|
387 |
+
"None",
|
388 |
+
7,
|
389 |
+
True,
|
390 |
+
"text",
|
391 |
+
False,
|
392 |
+
False,
|
393 |
+
"github.com, stackoverflow.com, medium.com",
|
394 |
+
"",
|
395 |
+
"None"
|
396 |
+
],
|
397 |
+
# Climate change news with exclusions
|
398 |
+
[
|
399 |
+
"Climate change policy updates",
|
400 |
+
"news",
|
401 |
+
"basic",
|
402 |
+
3,
|
403 |
+
4,
|
404 |
+
"month",
|
405 |
+
14,
|
406 |
+
True,
|
407 |
+
"false",
|
408 |
+
False,
|
409 |
+
False,
|
410 |
+
"",
|
411 |
+
"facebook.com, twitter.com, reddit.com",
|
412 |
+
"None"
|
413 |
+
],
|
414 |
+
# Country-specific search
|
415 |
+
[
|
416 |
+
"Best restaurants and food culture",
|
417 |
+
"general",
|
418 |
+
"basic",
|
419 |
+
3,
|
420 |
+
6,
|
421 |
+
"None",
|
422 |
+
7,
|
423 |
+
True,
|
424 |
+
"false",
|
425 |
+
True,
|
426 |
+
True,
|
427 |
+
"",
|
428 |
+
"",
|
429 |
+
"france"
|
430 |
+
],
|
431 |
+
# Technology news with images
|
432 |
+
[
|
433 |
+
"iPhone 15 features and specs",
|
434 |
+
"general",
|
435 |
+
"advanced",
|
436 |
+
3,
|
437 |
+
5,
|
438 |
+
"None",
|
439 |
+
7,
|
440 |
+
True,
|
441 |
+
"markdown",
|
442 |
+
True,
|
443 |
+
True,
|
444 |
+
"apple.com, techcrunch.com, theverge.com",
|
445 |
+
"",
|
446 |
+
"united states"
|
447 |
+
],
|
448 |
+
# Sports news recent
|
449 |
+
[
|
450 |
+
"FIFA World Cup 2024 results",
|
451 |
+
"news",
|
452 |
+
"advanced",
|
453 |
+
3,
|
454 |
+
7,
|
455 |
+
"day",
|
456 |
+
1,
|
457 |
+
True,
|
458 |
+
"text",
|
459 |
+
False,
|
460 |
+
False,
|
461 |
+
"fifa.com, espn.com, bbc.com",
|
462 |
+
"",
|
463 |
+
"None"
|
464 |
+
],
|
465 |
+
# Academic research
|
466 |
+
[
|
467 |
+
"quantum computing research papers 2024",
|
468 |
+
"general",
|
469 |
+
"advanced",
|
470 |
+
3,
|
471 |
+
10,
|
472 |
+
"year",
|
473 |
+
7,
|
474 |
+
True,
|
475 |
+
"markdown",
|
476 |
+
False,
|
477 |
+
False,
|
478 |
+
"arxiv.org, nature.com, science.org",
|
479 |
+
"wikipedia.org",
|
480 |
+
"None"
|
481 |
+
],
|
482 |
+
# Stock market news
|
483 |
+
[
|
484 |
+
"Tesla stock price analysis",
|
485 |
+
"news",
|
486 |
+
"basic",
|
487 |
+
3,
|
488 |
+
5,
|
489 |
+
"week",
|
490 |
+
7,
|
491 |
+
True,
|
492 |
+
"false",
|
493 |
+
False,
|
494 |
+
False,
|
495 |
+
"yahoo.com, bloomberg.com, marketwatch.com",
|
496 |
+
"",
|
497 |
+
"None"
|
498 |
+
],
|
499 |
+
# Health and medical
|
500 |
+
[
|
501 |
+
"COVID-19 vaccine effectiveness studies",
|
502 |
+
"general",
|
503 |
+
"advanced",
|
504 |
+
3,
|
505 |
+
8,
|
506 |
+
"month",
|
507 |
+
7,
|
508 |
+
True,
|
509 |
+
"text",
|
510 |
+
False,
|
511 |
+
False,
|
512 |
+
"who.int, cdc.gov, pubmed.ncbi.nlm.nih.gov",
|
513 |
+
"facebook.com, instagram.com",
|
514 |
+
"None"
|
515 |
+
]
|
516 |
+
],
|
517 |
+
inputs=[
|
518 |
+
query, topic, search_depth, chunks_per_source, max_results,
|
519 |
+
time_range, days, include_answer, include_raw_content, include_images,
|
520 |
+
include_image_descriptions, include_domains, exclude_domains, country
|
521 |
],
|
522 |
+
label="π Click on any example to load complete test configurations"
|
|
|
523 |
)
|
524 |
|
525 |
# Connect the search button
|