1 00:00:00,03 --> 00:00:02,01 - [Instructor] Now that we've seen the location tool, 2 00:00:02,01 --> 00:00:04,01 let's take a look at the weather tool. 3 00:00:04,01 --> 00:00:05,08 The weather tool is pretty straightforward. 4 00:00:05,08 --> 00:00:07,05 The only file that we need to import, 5 00:00:07,05 --> 00:00:09,07 the only library we need is requests 6 00:00:09,07 --> 00:00:13,02 because we're going to be using the Open-Meteo APIs. 7 00:00:13,02 --> 00:00:15,03 And this Open-Meteo API, as you can see here, 8 00:00:15,03 --> 00:00:16,09 just gives us a URL, 9 00:00:16,09 --> 00:00:18,08 that we pass it the latitude 10 00:00:18,08 --> 00:00:21,06 and the longitude of where we are, 11 00:00:21,06 --> 00:00:23,07 and then some other parameters, for example, 12 00:00:23,07 --> 00:00:27,02 like we want hourly weather, precipitation probability, 13 00:00:27,02 --> 00:00:30,07 weather code, stuff like that to come back from it. 14 00:00:30,07 --> 00:00:32,04 We're going to use requests 15 00:00:32,04 --> 00:00:34,08 to get that URL to get a response. 16 00:00:34,08 --> 00:00:36,07 If there's an error or a bad response, 17 00:00:36,07 --> 00:00:39,02 we understand that we're just going to exit out of here 18 00:00:39,02 --> 00:00:41,01 and say there's an error fetching the data. 19 00:00:41,01 --> 00:00:43,07 And again, our agent using this tool, 20 00:00:43,07 --> 00:00:47,02 if it sees an error, could come up with an alternate plan. 21 00:00:47,02 --> 00:00:49,01 But once we've done that and we get it back, 22 00:00:49,01 --> 00:00:53,02 then we want to get the weather for the day-to-day. 23 00:00:53,02 --> 00:00:55,08 And we're going to get that as a summary 24 00:00:55,08 --> 00:00:58,05 with that weather data that we've returned. 25 00:00:58,05 --> 00:01:00,00 So, to summarize the weather, 26 00:01:00,00 --> 00:01:01,05 I've made a couple of decisions here 27 00:01:01,05 --> 00:01:03,07 that one of them in particular would be... 28 00:01:03,07 --> 00:01:05,01 We want to hike, 29 00:01:05,01 --> 00:01:08,05 and we're generally going to be hiking in daytime hours. 30 00:01:08,05 --> 00:01:13,07 So, this code is going to take a look at today 31 00:01:13,07 --> 00:01:18,06 between 0800 and 1700, so between 8:00 AM and 5:00 PM, 32 00:01:18,06 --> 00:01:21,02 and use that to be able to get a summary 33 00:01:21,02 --> 00:01:24,00 of the daytime weather hours. 34 00:01:24,00 --> 00:01:26,01 So, once we've done that, 35 00:01:26,01 --> 00:01:28,09 this is how we're going to be able to generate, 36 00:01:28,09 --> 00:01:32,03 remember that English language forecast for the day 37 00:01:32,03 --> 00:01:35,01 that the engine would be able to reason across, 38 00:01:35,01 --> 00:01:39,04 because everything that the service is returning to me 39 00:01:39,04 --> 00:01:42,02 would be, for example, a table containing, 40 00:01:42,02 --> 00:01:43,08 at this time, it's this temperature, 41 00:01:43,08 --> 00:01:45,09 this precipitation probability. 42 00:01:45,09 --> 00:01:47,07 And that would be very useful to us. 43 00:01:47,07 --> 00:01:50,04 But I wanted to process this weather data 44 00:01:50,04 --> 00:01:53,08 to get that concise summary for today's hours. 45 00:01:53,08 --> 00:01:55,06 So, that's all this code is doing here, 46 00:01:55,06 --> 00:01:57,02 is that it's looking at the data 47 00:01:57,02 --> 00:02:00,00 that it was getting back in this response 48 00:02:00,00 --> 00:02:01,08 from the weather API 49 00:02:01,08 --> 00:02:06,02 and turning that into a decent English language summary 50 00:02:06,02 --> 00:02:07,09 of the weather for today 51 00:02:07,09 --> 00:02:10,07 between the hours of 8:00 AM and 5:00 PM. 52 00:02:10,07 --> 00:02:13,02 All this code is very specific to that API. 53 00:02:13,02 --> 00:02:15,09 You could go into more detail by looking at that API. 54 00:02:15,09 --> 00:02:18,08 I'm not going to waste your time by going into that detail now, 55 00:02:18,08 --> 00:02:20,05 but that's just the important part here, 56 00:02:20,05 --> 00:02:23,01 is that the idea was to get that summary 57 00:02:23,01 --> 00:02:24,07 for the daylight hours 58 00:02:24,07 --> 00:02:28,02 and then return that here as this weather description. 59 00:02:28,02 --> 00:02:30,07 So, the weather description comes 60 00:02:30,07 --> 00:02:32,06 from a number of these codes. 61 00:02:32,06 --> 00:02:34,05 This service will return these codes. 62 00:02:34,05 --> 00:02:38,06 So, for example, if it was to return code number 73, 63 00:02:38,06 --> 00:02:41,00 the text for that is moderate snowfall. 64 00:02:41,00 --> 00:02:44,09 And I want the AI to be able to reason across the text, 65 00:02:44,09 --> 00:02:47,01 rather than having to deal with a code. 66 00:02:47,01 --> 00:02:50,09 So, this is where the weather tool is taking those codes 67 00:02:50,09 --> 00:02:53,02 that are from the Open-Meteo 68 00:02:53,02 --> 00:02:55,04 and turning that into that summary 69 00:02:55,04 --> 00:02:57,01 that we saw an example of earlier on 70 00:02:57,01 --> 00:02:59,03 that's saying today is 20 degrees, 71 00:02:59,03 --> 00:03:02,02 average temperature of 20 degrees, it's going to be sunny 72 00:03:02,02 --> 00:03:05,01 and a maximum precipitation probability of whatever, 73 00:03:05,01 --> 00:03:08,08 so that the service has something to reason across. 74 00:03:08,08 --> 00:03:10,08 And I've also made this to be... 75 00:03:10,08 --> 00:03:13,01 You could use it as a standalone if you want to test it, 76 00:03:13,01 --> 00:03:16,00 where I've just hard coded some latitude and longitude 77 00:03:16,00 --> 00:03:22,02 so we can run it and see how it looks. 78 00:03:22,02 --> 00:03:25,02 I do that here by running python weather.py. 79 00:03:25,02 --> 00:03:27,04 And for that latitude and longitude, 80 00:03:27,04 --> 00:03:29,06 today's forecast, clear sky, 81 00:03:29,06 --> 00:03:32,03 if you remember clear sky here 82 00:03:32,03 --> 00:03:34,02 should correlate to... 83 00:03:34,02 --> 00:03:37,01 Yep, the WMO code zero here. 84 00:03:37,01 --> 00:03:40,06 The API returns that WMO code. 85 00:03:40,06 --> 00:03:44,04 I chose that one and turned that into English language. 86 00:03:44,04 --> 00:03:45,08 And then the average temperature 87 00:03:45,08 --> 00:03:47,07 was the temperature if we looked at 88 00:03:47,07 --> 00:03:49,08 the data that came back from the service 89 00:03:49,08 --> 00:03:52,00 between the hours of 8:00 AM and 5:00 PM 90 00:03:52,00 --> 00:03:53,04 and averaged that out. 91 00:03:53,04 --> 00:03:54,09 And then we took a look at 92 00:03:54,09 --> 00:03:57,03 the maximum precipitation probability again, 93 00:03:57,03 --> 00:04:00,03 looking through the table of data that the service returned, 94 00:04:00,03 --> 00:04:03,04 and in this case, found the maximum probability of 0%, 95 00:04:03,04 --> 00:04:07,02 so we get that really nice English language forecast 96 00:04:07,02 --> 00:04:10,03 that the AI model could reason across. 97 00:04:10,03 --> 00:04:12,02 So, that's it for the weather tool. 98 00:04:12,02 --> 00:04:14,02 Pretty straightforward, as you can see. 99 00:04:14,02 --> 00:04:15,08 But the next video, we're going to then 100 00:04:15,08 --> 00:04:18,00 take a look at our final and most important tool, 101 00:04:18,00 --> 00:04:21,00 and that's the one that's for the park's APIs.