Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

fix tavily tool #617

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 66 additions & 29 deletions llama_hub/tools/notebooks/tavily.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"source": [
"# Building a Tavily Data Agent\n",
"\n",
"<a href=\"https://colab.research.google.com/github/run-llama/llama-hub/blob/main/llama_hub/tools/notebooks/tavily.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\n",
"\n",
"This tutorial walks through using the LLM tools provided by the [Tavily API](https://app.tavily.com/) to allow LLMs to easily search and retrieve relevant content from the Internet.\n",
"\n",
"To get started, you will need an [OpenAI api key](https://platform.openai.com/account/api-keys) and a [Tavily API key](https://app.tavily.com)\n",
Expand All @@ -16,8 +18,50 @@
},
{
"cell_type": "code",
"execution_count": 3,
"id": "df2a0ecd-22e9-4cef-b069-89e4286e4d75",
"execution_count": null,
"id": "e6b2678c-09a5-4bf5-b45a-0543d2c100f9",
"metadata": {},
"outputs": [],
"source": [
"!pip install llama-index llama-hub tavily-python"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ce6c6e5d-f61e-461e-8e8d-99d27fb3fcaf",
"metadata": {
"ExecuteTime": {
"end_time": "2023-10-25T09:55:23.881158Z",
"start_time": "2023-10-25T09:55:23.865840Z"
}
},
"outputs": [],
"source": [
"# Set up OpenAI\n",
"import openai\n",
"from llama_index.agent import OpenAIAgent"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0c90f5ea-9ed0-43c5-a658-1a3d93382eaa",
"metadata": {
"ExecuteTime": {
"end_time": "2023-10-25T09:55:23.881158Z",
"start_time": "2023-10-25T09:55:23.865840Z"
}
},
"outputs": [],
"source": [
"openai.api_key = \"sk-api-key\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3ab26eee-63ed-42ec-972a-419a9a5c1d82",
"metadata": {
"ExecuteTime": {
"end_time": "2023-10-25T09:55:23.881158Z",
Expand All @@ -34,14 +78,8 @@
}
],
"source": [
"# Set up OpenAI\n",
"import openai\n",
"from llama_index.agent import OpenAIAgent\n",
"\n",
"openai.api_key = \"sk-api-key\"\n",
"\n",
"# Set up Tavily tool\n",
"from llama_hub.tools.tavily.base import TavilyToolSpec\n",
"from llama_hub.tools.tavily_research.base import TavilyToolSpec\n",
"\n",
"tavily_tool = TavilyToolSpec(\n",
" api_key=\"tvly-api-key\",\n",
Expand Down Expand Up @@ -76,9 +114,9 @@
{
"data": {
"text/plain": [
"[Document(id_='8038fd7d-10dc-4d7a-b535-51b2b56f7c3e', embedding=None, metadata={'url': 'https://www.npr.org/2023/09/05/1197587557/burning-man-exodus-2023-mud'}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, hash='be58b5ad268c8d25cd4961eaa603e4ec5d0a56ce994222bb8a1315e1d572e5d4', text=',\\nChloe Veltman\\nVehicles seen departing the Burning Man festival in Black Rock City, Nev., on Monday.\\nMatt Mills McKnight/Reuters\\nhide caption\\n\\nNational\\nThe latest on the Burning Man flooding\\nSome frustration, however, started to seep in for some attendees by Sunday.\\n\\nCulture\\nBurning Man festival organizers lift driving ban and allow people to leave\\n\\nhide caption\\nVehicles seen departing the Burning Man festival in Black Rock City, Nev., on Monday.\\n\\nEvent volunteer Josh Lease said that in true Burning Man spirit, people were sharing warm clothes and phone chargers where they could — and they kept the music blaring.', start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n'),\n",
" Document(id_='792a9e12-8de7-40de-9710-824b04e6e10c', embedding=None, metadata={'url': 'https://www.insider.com/explainer-everything-that-went-wrong-burning-man-festival-so-far-2023-9'}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, hash='246ed39cfaca5d8f5a5a365d7779de0e3b9b6fa7594b4b9041e39bac11174bbd', text='And now,\\xa0tens of thousands of Burning Man attendees are stranded due to a rainstorm that turned the desert into a mud pit.\\nHere\\'s how Burning Man 2023 has played out so far.\\n\\nJump to\\nEverything that went wrong at Burning Man 2023, so far\\nThe year\\'s Burning Man is off to a rocky start.\\n\\nA Burning Man festival organizer told Insider in a statement that organizers conducted \"table-top drills for events like this\" and are working to provide an exit for stranded attendees.\\n\\nto an X post from Burning Man Traffic, a social media account that shares updates about the campsite.\\n\\nThe Guardian reported that four protesters were arrested, and local authorities removed the blockade.\\nBurning Man advised guests to shelter in place and preserve resources as bad weather continued.', start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n'),\n",
" Document(id_='e2868174-2ea2-444a-8571-28ce840ef47f', embedding=None, metadata={'url': 'https://www.billboard.com/culture/events/burning-man-2023-disaster-recap-1235407933/'}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, hash='97de1e53e980fbf8b56772a6d76a5f89f283bec7954d6b049c370fc164ccde54', text=\"At around 4 a.m. last Saturday an unusual thing happened at Burning Man. The event, typically an all-hours hubbub of music, art cars, laughter, weeping, whirring bikes, bass drops and other assorted\\n\\nBurning Man 2023: Relatively Normal, Honestly\\xa0Great\\nThe 2023 gathering in Nevada's Black Rock Desert was called a disaster, but that didn't feel true for those on the inside of it.\\nBy\\nKatie Bain\\n\\nthe next few days of our collective existence became a question mark. But also, uncertainty is exciting, and why go to Burning Man but for an unconventional experience? There was a buzz in the air\\n\\nany type of vehicle without getting stuck or, worse, slice ruts in the roads making driving difficult once the ground dried. I’ve been to Burning Man eight times\\xa0— for fun, for adventure, for work.\\n\\nthe flooded tents and Burners with plastic grocery bags duct taped around their shoes, one couldn’t help but laugh. Or cry. Or both.\", start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n')]"
"[Document(id_='47fad889-3ced-4a91-bc4b-8af9939c6535', embedding=None, metadata={'url': 'https://www.vox.com/culture/2023/9/6/23861675/burning-man-2023-mud-stranded-climate-change-playa-foot'}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, hash='879353cf1df00d8e20618086e44683d83ed17bf093524e2ef60ac111291d6094', text='Has Burning Man finally lost its glamour?\\n\\nGive\\nNewsletters\\nSite search\\nVox main menu\\nFiled under:\\nThe Burning Man flameout, explained\\nClimate change — and schadenfreude\\xa0— finally caught up to the survivalist cosplayers.\\nShare this story\\nShare\\n\\nSeptember 1, after most of the scheduled events and live performances were canceled due to the weather, Burning Man organizers closed routes in and out of the area, forcing attendees to stay behind\\n\\nShare\\nAll sharing options for:\\nThe Burning Man flameout, explained\\n\\nFor most of its existence, Burning Man, the week-long desert experience that’s part utopian performance, part survival quest, and part drug trip, has dodged serious cultural pushback, beyond eye', start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n'),\n",
" Document(id_='e26008c2-508e-42bc-b7bb-5e75ba8d450b', embedding=None, metadata={'url': 'https://www.insider.com/photos-what-it-was-really-like-at-burning-man-2023-2023-9'}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, hash='612b38bc411db0a05acd7dc5e9cc335743e307427527e5cb5f25aeb57a8bbeb6', text='I\\'ve seen Burning Man 2023 called a \"total disaster\" and \"Fyre Festival 2.0.\" I\\'ve read stories about people \"clamoring to escape\" and leaving behind their cars and trash.\\n\\nMy first days at Burning Man featured plenty of parties.\\nBurning Man is known for its incredible art and music, and we spent the first few days exploring as much of it as possible.\\n\\nI went to Burning Man for the first time and it was one of the best weeks of my life.\\n\\nThe bulk of my incredible Burning Man experience was due to Android Oasis, once a six-person crew of friends that has since blossomed into a 70-person camp.\\n\\nI found myself dancing in everything from a towering pyramid to a fluffy cloud.\\nLife at Burning Man often felt like living in a video game —\\xa0or a fairy tale.', start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n'),\n",
" Document(id_='83b1399d-b9d9-4f7c-9351-49666785e4a4', embedding=None, metadata={'url': 'https://www.insider.com/photos-what-it-was-really-like-at-burning-man-2023-2023-9'}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, hash='612b38bc411db0a05acd7dc5e9cc335743e307427527e5cb5f25aeb57a8bbeb6', text='I\\'ve seen Burning Man 2023 called a \"total disaster\" and \"Fyre Festival 2.0.\" I\\'ve read stories about people \"clamoring to escape\" and leaving behind their cars and trash.\\n\\nMy first days at Burning Man featured plenty of parties.\\nBurning Man is known for its incredible art and music, and we spent the first few days exploring as much of it as possible.\\n\\nI went to Burning Man for the first time and it was one of the best weeks of my life.\\n\\nThe bulk of my incredible Burning Man experience was due to Android Oasis, once a six-person crew of friends that has since blossomed into a 70-person camp.\\n\\nI found myself dancing in everything from a towering pyramid to a fluffy cloud.\\nLife at Burning Man often felt like living in a video game —\\xa0or a fairy tale.', start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n')]"
]
},
"execution_count": 4,
Expand Down Expand Up @@ -119,7 +157,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "f69a53fd-55c4-4e18-8fbe-6a29d5f3cef0",
"metadata": {
"ExecuteTime": {
Expand All @@ -135,26 +173,25 @@
"# Analysis of the Latest Burning Man Floods\n",
"\n",
"## Introduction\n",
"The Burning Man festival, held annually in the Black Rock Desert of Nevada, is known for its unique art installations, music performances, and community spirit. However, in recent years, the festival has faced challenges due to extreme weather conditions, including floods. This analysis aims to provide a deep understanding of the latest Burning Man floods, their causes, impacts, and potential solutions.\n",
"The Burning Man festival, held annually in the Black Rock Desert of Nevada, is known for its unique art installations, music performances, and community spirit. However, in recent years, the festival has faced challenges due to extreme weather conditions, including floods. This analysis aims to provide a deep understanding of the latest Burning Man floods, their causes, impacts, and the response of the festival organizers.\n",
"\n",
"## Overview of the Latest Burning Man Floods\n",
"According to a [news article](https://www.today.com/news/what-is-burning-man-flood-death-rcna103231), the latest Burning Man festival experienced heavy rains that resulted in muddy conditions, making it difficult for festivalgoers to leave the Nevada desert. The article mentions that tens of thousands of festival attendees were slowly making their way home as the muddy conditions made it nearly impossible to leave over the weekend. The festival organizers provided a \"Wet Playa Survival Guide\" with tips to those still on-site, indicating that the conditions were improving.\n",
"\n",
"## Causes of the Floods\n",
"1. Heavy Rainfall: The primary cause of the floods at Burning Man is heavy rainfall. The desert region where the festival takes place is typically arid, but occasional rainstorms can result in significant amounts of water accumulating on the playa.\n",
"2. Poor Drainage System: The infrastructure at Burning Man is not designed to handle large amounts of rainfall. The lack of an efficient drainage system exacerbates the flooding problem, as the water has no proper outlet to flow away from the festival grounds.\n",
"3. Climate Change: The increasing frequency and intensity of extreme weather events, including heavy rainfall, can be attributed to climate change. As global temperatures rise, the likelihood of extreme weather events occurring during the festival also increases.\n",
"1. Heavy Rainfall: The primary cause of the floods at Burning Man was heavy rainfall. The article mentions that the festival experienced significant rain, leading to muddy conditions and making it challenging for attendees to navigate the desert.\n",
"2. Flash Floods: The Black Rock Desert is prone to flash floods due to its flat topography and lack of vegetation. When rainwater accumulates faster than it can be absorbed or evaporated, it quickly forms torrents that flood the festival grounds.\n",
"\n",
"## Impacts of the Floods\n",
"1. Damage to Art Installations: The floods can cause significant damage to the intricate and often fragile art installations at Burning Man. The water can erode structures, ruin electronic components, and render artworks unsalvageable.\n",
"2. Safety Concerns: The floods pose safety risks to festival attendees. Standing water can create slippery conditions, increasing the likelihood of accidents and injuries. Additionally, flash floods can occur suddenly, catching people off guard and potentially leading to dangerous situations.\n",
"3. Disruption of Activities: The floods can disrupt scheduled performances, workshops, and other activities at Burning Man. The festival relies on a carefully planned itinerary, and any interruptions due to flooding can result in disappointment and logistical challenges.\n",
"1. Transportation Challenges: The muddy conditions caused by the floods made it difficult for festivalgoers to leave the desert. This created transportation challenges and delays for tens of thousands of attendees.\n",
"2. Disruption of Activities: The floods disrupted the planned activities and performances at Burning Man. The muddy conditions may have made it challenging for artists and performers to showcase their work, impacting the overall experience of the festival.\n",
"3. Safety Risks: The muddy and slippery conditions posed safety risks to festival attendees. The article does not mention any specific incidents, but the increased risk of slips, falls, and injuries is a concern during such weather conditions.\n",
"\n",
"## Response and Mitigation Measures\n",
"1. Improved Drainage System: One of the key solutions to address the flooding issue is the implementation of a more robust and efficient drainage system. This would involve creating channels or trenches to direct water away from the festival grounds, preventing it from accumulating and causing floods.\n",
"2. Weather Monitoring and Early Warning Systems: Installing weather monitoring equipment and establishing early warning systems can help organizers anticipate and prepare for potential floods. This would allow them to take proactive measures, such as evacuating certain areas or rescheduling activities, to ensure the safety of attendees.\n",
"3. Artwork Protection Measures: Artists and organizers can take steps to protect art installations from flood damage. This may include using waterproof materials, elevating structures, or designing installations that can withstand water exposure.\n",
"4. Climate Change Adaptation: Given the role of climate change in exacerbating extreme weather events, it is crucial for Burning Man organizers to consider long-term adaptation strategies. This may involve exploring alternative locations less prone to flooding or implementing sustainable practices to mitigate the festival's carbon footprint.\n",
"## Response of the Festival Organizers\n",
"The article does not provide detailed information about the specific response of the festival organizers to the floods. However, it mentions that the festival organizers provided a \"Wet Playa Survival Guide\" with tips to those still on-site, indicating that they were actively addressing the challenges posed by the floods. It is likely that the organizers were monitoring the situation, providing updates, and taking necessary measures to ensure the safety and well-being of the attendees.\n",
"\n",
"## Conclusion\n",
"The latest Burning Man floods highlight the vulnerability of the festival to extreme weather events. Addressing the causes and impacts of these floods requires a multi-faceted approach, including improved infrastructure, enhanced monitoring systems, and climate change adaptation measures. By implementing these solutions, Burning Man can continue to thrive as a unique and vibrant event while ensuring the safety and preservation of its art and community.\n"
"The latest Burning Man floods, caused by heavy rainfall and resulting in muddy conditions, created challenges for festivalgoers and disrupted the planned activities at the event. The transportation difficulties, disruption of activities, and safety risks highlight the impact of extreme weather events on the festival. While the specific response of the festival organizers is not detailed in the available information, it can be assumed that they took measures to address the challenges and ensure the safety of the attendees. As extreme weather events become more frequent and intense, it is crucial for the festival organizers to continue evaluating and implementing strategies to mitigate the impact of floods and other weather-related challenges at Burning Man.\n"
]
}
],
Expand All @@ -173,9 +210,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "llama_hub",
"language": "python",
"name": "python3"
"name": "llama_hub"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -187,7 +224,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions llama_hub/tools/tavily_research/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class TavilyToolSpec(BaseToolSpec):

def __init__(self, api_key: str) -> None:
"""Initialize with parameters."""
from tavily import TavilyClient
from tavily import Client

self.client = TavilyClient(api_key=api_key)
self.client = Client(api_key=api_key)

def search(self, query: str, max_results: Optional[int] = 6) -> List[Document]:
"""
Expand Down