- [Instructor] Now that we've seen the location tool,
let's take a look at the weather tool.
The weather tool is pretty straightforward.
The only file that we need to import,
the only library we need is requests
because we're going to be using the Open-Meteo APIs.
And this Open-Meteo API, as you can see here,
just gives us a URL,
that we pass it the latitude
and the longitude of where we are,
and then some other parameters, for example,
like we want hourly weather, precipitation probability,
weather code, stuff like that to come back from it.
We're going to use requests
to get that URL to get a response.
If there's an error or a bad response,
we understand that we're just going to exit out of here
and say there's an error fetching the data.
And again, our agent using this tool,
if it sees an error, could come up with an alternate plan.
But once we've done that and we get it back,
then we want to get the weather for the day-to-day.
And we're going to get that as a summary
with that weather data that we've returned.
So, to summarize the weather,
I've made a couple of decisions here
that one of them in particular would be...
We want to hike,
and we're generally going to be hiking in daytime hours.
So, this code is going to take a look at today
between 0800 and 1700, so between 8:00 AM and 5:00 PM,
and use that to be able to get a summary
of the daytime weather hours.
So, once we've done that,
this is how we're going to be able to generate,
remember that English language forecast for the day
that the engine would be able to reason across,
because everything that the service is returning to me
would be, for example, a table containing,
at this time, it's this temperature,
this precipitation probability.
And that would be very useful to us.
But I wanted to process this weather data
to get that concise summary for today's hours.
So, that's all this code is doing here,
is that it's looking at the data
that it was getting back in this response
from the weather API
and turning that into a decent English language summary
of the weather for today
between the hours of 8:00 AM and 5:00 PM.
All this code is very specific to that API.
You could go into more detail by looking at that API.
I'm not going to waste your time by going into that detail now,
but that's just the important part here,
is that the idea was to get that summary
for the daylight hours
and then return that here as this weather description.
So, the weather description comes
from a number of these codes.
This service will return these codes.
So, for example, if it was to return code number 73,
the text for that is moderate snowfall.
And I want the AI to be able to reason across the text,
rather than having to deal with a code.
So, this is where the weather tool is taking those codes
that are from the Open-Meteo
and turning that into that summary
that we saw an example of earlier on
that's saying today is 20 degrees,
average temperature of 20 degrees, it's going to be sunny
and a maximum precipitation probability of whatever,
so that the service has something to reason across.
And I've also made this to be...
You could use it as a standalone if you want to test it,
where I've just hard coded some latitude and longitude
so we can run it and see how it looks.
I do that here by running python weather.py.
And for that latitude and longitude,
today's forecast, clear sky,
if you remember clear sky here
should correlate to...
Yep, the WMO code zero here.
The API returns that WMO code.
I chose that one and turned that into English language.
And then the average temperature
was the temperature if we looked at
the data that came back from the service
between the hours of 8:00 AM and 5:00 PM
and averaged that out.
And then we took a look at
the maximum precipitation probability again,
looking through the table of data that the service returned,
and in this case, found the maximum probability of 0%,
so we get that really nice English language forecast
that the AI model could reason across.
So, that's it for the weather tool.
Pretty straightforward, as you can see.
But the next video, we're going to then
take a look at our final and most important tool,
and that's the one that's for the park's APIs.