From e46be65707a048fa4571fa5577af1faa9232bd1e Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 10 May 2024 18:31:24 +0200 Subject: [PATCH] feat: Add optional location name to weather report This update allows users to provide a location name for their weather reports, which can be useful when requesting weather information for specific locations. --- src/gptbot/tools/weather.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gptbot/tools/weather.py b/src/gptbot/tools/weather.py index 30e239e..5defc98 100644 --- a/src/gptbot/tools/weather.py +++ b/src/gptbot/tools/weather.py @@ -17,6 +17,10 @@ class Weather(BaseTool): "type": "string", "description": "The longitude of the location.", }, + "name": { + "type": "string", + "description": "A location name to include in the report. This is optional, latitude and longitude are always required." + } }, "required": ["latitude", "longitude"], } @@ -26,6 +30,8 @@ class Weather(BaseTool): if not (latitude := self.kwargs.get("latitude")) or not (longitude := self.kwargs.get("longitude")): raise Exception('No location provided.') + name = self.kwargs.get("name") + weather_api_key = self.bot.config.get("OpenWeatherMap", "APIKey") if not weather_api_key: @@ -37,7 +43,7 @@ class Weather(BaseTool): async with session.get(url) as response: if response.status == 200: data = await response.json() - return f"""**Weather report** + return f"""**Weather report{f" for {name}" if name else ""}** Current: {data['current']['temp']}°C, {data['current']['weather'][0]['description']} Feels like: {data['current']['feels_like']}°C Humidity: {data['current']['humidity']}%