diff --git a/docs/docs/integrations/tools/bing_search.ipynb b/docs/docs/integrations/tools/bing_search.ipynb index 4756013a66..a8ff317167 100644 --- a/docs/docs/integrations/tools/bing_search.ipynb +++ b/docs/docs/integrations/tools/bing_search.ipynb @@ -30,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -186,7 +186,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -195,7 +195,7 @@ "BingSearchResults(api_wrapper=BingSearchAPIWrapper(bing_subscription_key='', bing_search_url='https://api.bing.microsoft.com/v7.0/search', k=10, search_kwargs={}))" ] }, - "execution_count": 10, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -213,24 +213,27 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'snippet': 'This chart shows the 14 day weather trend for 33.74°N 89.59°E with daily weather symbols, minimum and maximum temperatures, precipitation amount and probability.. The deviance is coloured within the temperature graph. The stronger the ups and downs, the more uncertain the forecast will be.', 'title': '14 Day Weather 33.74°N 89.59°E - meteoblue', 'link': 'https://www.meteoblue.com/en/weather/14-days/33.739N89.594E6216_Asia%2FShanghai'}\n", - "{'snippet': 'Get the monthly weather forecast for Huangpu District, Shanghai, China, including daily high/low, historical averages, to help you plan ahead.', 'title': 'Huangpu District, Shanghai, China Monthly Weather | AccuWeather', 'link': 'https://www.accuweather.com/en/cn/huangpu-district/60782/june-weather/60782'}\n", - "{'snippet': 'Shanghai Hongqiao Airport is 60 miles from 31°31'42.7"N, 120°24'12.7"E, so the actual climate in 31°31'42.7"N, 120°24'12.7"E can vary a bit. Based on weather reports collected during 1992–2021. Showing: All Year January February March April May June July August September October November December', 'title': 'Climate & Weather Averages in 31°31'42.7"N, 120°24'12.7"E, China', 'link': 'https://www.timeanddate.com/weather/@31.52853,120.40355/climate'}\n", - "{'snippet': 'Air Quality gives information using weather conditions, pollutants, and research from The Weather Channel and weather.com ... Today's Air Quality-Shanghai, People's Republic of China. 76.', 'title': 'Shanghai, People's Republic of China Weather', 'link': 'https://weather.com/forecast/air-quality/l/80415bb74d7ded500f89b569c51da53325719ddea6e1394485ad846e812e61d2'}\n" + "{'snippet': 'Shanghai, Shanghai, China Weather Forecast, with current conditions, wind, air quality, and what to expect for the next 3 days.', 'title': 'Shanghai, Shanghai, China Weather Forecast | AccuWeather', 'link': 'https://www.accuweather.com/en/cn/shanghai/106577/weather-forecast/106577'}\n", + "{'snippet': 'Current weather in Shanghai and forecast for today, tomorrow, and next 14 days', 'title': 'Weather for Shanghai, Shanghai Municipality, China - timeanddate.com', 'link': 'https://www.timeanddate.com/weather/china/shanghai'}\n", + "{'snippet': 'Shanghai 14 Day Extended Forecast. Weather Today Weather Hourly 14 Day Forecast Yesterday/Past Weather Climate (Averages) Currently: 73 °F. Rain showers. Partly sunny. (Weather station: Shanghai Hongqiao Airport, China). See more current weather.', 'title': 'Shanghai, Shanghai Municipality, China 14 day weather forecast', 'link': 'https://www.timeanddate.com/weather/china/shanghai/ext'}\n", + "{'snippet': 'Shanghai - Weather warnings issued 14-day forecast. Weather warnings issued. Forecast - Shanghai. Day by day forecast. Last updated today at 18:00. Tonight, A clear sky and a gentle breeze. Clear Sky.', 'title': 'Shanghai - BBC Weather', 'link': 'https://www.bbc.com/weather/1796236'}\n" ] } ], "source": [ + "import json\n", + "\n", "# .invoke wraps utility.results\n", - "response = tool.invoke(\"What is the weather in Shanghai\")\n", - "for item in list(response):\n", + "response = tool.invoke(\"What is the weather in Shanghai?\")\n", + "response = json.loads(response.replace(\"'\", '\"'))\n", + "for item in response:\n", " print(item)" ] }, @@ -255,7 +258,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -269,7 +272,7 @@ "Invoking: `bing_search_results_json` with `{'query': 'latest burning man floods'}`\n", "\n", "\n", - "\u001b[0m\u001b[36;1m\u001b[1;3m[{'snippet': 'Some festivalgoers have shared stories of their successful 6-mile hikes away from Burning Man. The worst of the rain Sunday is expected between 12 p.m. and 4 p.m. local time (3 p.m. to 7 p.m. ET ...', 'title': 'Live updates: Burning Man festival rain strands thousands in ... - CNN', 'link': 'https://www.cnn.com/us/live-news/nevada-desert-burning-man-weather-rain-09-03-23/index.html'}, {'snippet': 'Black Rock Forest, where around 70,000 Burning Man attendees are gathered for the festival, is in the northwest. "Flash flooding caused by excessive rainfall" is possible in parts of eastern ...', 'title': 'Burning Man flooding keeps thousands stranded at Nevada site as ...', 'link': 'https://www.nbcnews.com/news/us-news/live-blog/live-updates-burning-man-flooding-keeps-thousands-stranded-nevada-site-rcna103193'}, {'snippet': 'Thousands of Burning Man attendees finally made their mass exodus after intense rain over the weekend flooded camp sites and filled them with thick, ankle-deep mud – stranding more than 70,000 ...', 'title': 'Burning Man attendees make a mass exodus after a dramatic weekend ... - CNN', 'link': 'https://www.cnn.com/2023/09/05/us/burning-man-storms-shelter-exodus-tuesday/index.html'}, {'snippet': 'You’re going to get stuck,” hosts on Burning Man Information Radio, broadcasting from within the event, told festivalgoers early on Sept. 4. According to NBC News, the Pershing County Sheriff ...', 'title': 'Burning Man attendees make mass exodus after being stranded in ... - TODAY', 'link': 'https://www.today.com/news/what-is-burning-man-flood-death-rcna103231'}]\u001b[0m\u001b[32;1m\u001b[1;3mThe latest Burning Man festival experienced heavy rain and flooding, which resulted in thousands of festivalgoers being stranded. Some attendees had to hike for miles to safety. The rain caused flash flooding in parts of the festival site, including the Black Rock Forest where the event takes place. Campsites were flooded, and thick mud made movement difficult. Eventually, after the intense rain over the weekend, attendees were able to make a mass exodus from the festival. The Pershing County Sheriff's Office warned festivalgoers about the flooding and encouraged them to leave for safety.\u001b[0m\n", + "\u001b[0m\u001b[36;1m\u001b[1;3m[{'snippet': 'Live Updates. Thousands stranded at Burning Man festival after heavy rains. By Maureen Chowdhury, Steve Almasyand Matt Meyer, CNN. Updated 9:00 PM EDT, Sun September 3, 2023. Link Copied!', 'title': 'Thousands stranded at Burning Man festival after heavy rains', 'link': 'https://www.cnn.com/us/live-news/nevada-desert-burning-man-weather-rain-09-03-23/index.html'}, {'snippet': 'Black Rock Forest, where around 70,000 Burning Man attendees are gathered for the festival, is in the northwest. "Flash flooding caused by excessive rainfall" is possible in parts of eastern ...', 'title': 'Burning Man flooding keeps thousands stranded at Nevada site as ...', 'link': 'https://www.nbcnews.com/news/us-news/live-blog/live-updates-burning-man-flooding-keeps-thousands-stranded-nevada-site-rcna103193'}, {'snippet': 'Thousands of Burning Man attendees finally made their mass exodus after intense rain over the weekend flooded camp sites and filled them with thick, ankle-deep mud – stranding more than 70,000 ...', 'title': 'Burning Man attendees make a mass exodus after a dramatic weekend ... - CNN', 'link': 'https://www.cnn.com/2023/09/05/us/burning-man-storms-shelter-exodus-tuesday/index.html'}, {'snippet': 'FILE - In this satellite photo provided by Maxar Technologies, an overview of Burning Man festival in Black Rock, Nev on Monday, Aug. 28, 2023. Authorities in Nevada were investigating a death at the site of the Burning Man festival where thousands of attendees remained stranded as flooding from storms swept through the Nevada desert.', 'title': 'Wait times to exit Burning Man drop after flooding left tens of ...', 'link': 'https://apnews.com/article/burning-man-flooding-nevada-stranded-0726190c9f8378935e2a3cce7f154785'}]\u001b[0m\u001b[32;1m\u001b[1;3mIn the latest Burning Man festival, heavy rains caused flooding and resulted in thousands of attendees being stranded. The festival took place in Black Rock Forest, Nevada, and around 70,000 people were gathered for the event. The excessive rainfall led to flash flooding in some parts of the area. As a result, camp sites were filled with ankle-deep mud, making it difficult for people to leave. Authorities were investigating a death at the festival site, which was affected by the flooding. However, in the following days, thousands of Burning Man attendees were able to make a mass exodus after the rain subsided.\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n" ] @@ -278,10 +281,10 @@ "data": { "text/plain": [ "{'input': 'What happened in the latest burning man floods?',\n", - " 'output': \"The latest Burning Man festival experienced heavy rain and flooding, which resulted in thousands of festivalgoers being stranded. Some attendees had to hike for miles to safety. The rain caused flash flooding in parts of the festival site, including the Black Rock Forest where the event takes place. Campsites were flooded, and thick mud made movement difficult. Eventually, after the intense rain over the weekend, attendees were able to make a mass exodus from the festival. The Pershing County Sheriff's Office warned festivalgoers about the flooding and encouraged them to leave for safety.\"}" + " 'output': 'In the latest Burning Man festival, heavy rains caused flooding and resulted in thousands of attendees being stranded. The festival took place in Black Rock Forest, Nevada, and around 70,000 people were gathered for the event. The excessive rainfall led to flash flooding in some parts of the area. As a result, camp sites were filled with ankle-deep mud, making it difficult for people to leave. Authorities were investigating a death at the festival site, which was affected by the flooding. However, in the following days, thousands of Burning Man attendees were able to make a mass exodus after the rain subsided.'}" ] }, - "execution_count": 15, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -291,7 +294,7 @@ "import os\n", "\n", "from langchain import hub\n", - "from langchain.agents import AgentExecutor, create_openai_functions_agent\n", + "from langchain.agents import AgentExecutor, create_tool_calling_agent\n", "from langchain_openai import AzureChatOpenAI\n", "\n", "os.environ[\"AZURE_OPENAI_API_KEY\"] = getpass.getpass()\n", @@ -310,7 +313,7 @@ ")\n", "tool = BingSearchResults(api_wrapper=api_wrapper)\n", "tools = [tool]\n", - "agent = create_openai_functions_agent(llm, tools, prompt)\n", + "agent = create_tool_calling_agent(llm, tools, prompt)\n", "agent_executor = AgentExecutor(\n", " agent=agent,\n", " tools=tools,\n",