diff --git a/bot/functions.py b/bot/functions.py index 50d90bf..eb1e8b2 100644 --- a/bot/functions.py +++ b/bot/functions.py @@ -18,6 +18,6 @@ async def call_function(function_name, arguments): """ if function_name == "get_current_weather": arguments = json.loads(arguments) - return await get_current_weather(arguments["location"], arguments["unit"]) + return await get_current_weather(arguments["latitude"], arguments["longitude"], arguments["unit"]) raise Exception(f"Function {function_name} not found") diff --git a/plugins/weather.py b/plugins/weather.py index 3338244..8d2892d 100644 --- a/plugins/weather.py +++ b/plugins/weather.py @@ -1,7 +1,6 @@ import json import requests -from geopy import Nominatim def weather_function_spec(): @@ -11,9 +10,13 @@ def weather_function_spec(): "parameters": { "type": "object", "properties": { - "location": { + "latitude": { "type": "string", - "description": "The exact city and state, e.g. San Francisco, CA" + "description": "Latitude of the location" + }, + "longitude": { + "type": "string", + "description": "Longitude of the location" }, "unit": { "type": "string", @@ -21,24 +24,23 @@ def weather_function_spec(): "description": "The temperature unit to use. Infer this from the provided location.", }, }, - "required": ["location", "unit"], + "required": ["latitude", "longitude", "unit"], } } -async def get_current_weather(location, unit): +async def get_current_weather(latitude, longitude, unit): """ Get the current weather in a given location using the Open Meteo API Source: https://open-meteo.com/en/docs - :param location: The location to get the weather for, in natural language + :param latitude: The latitude of the location to get the weather for + :param longitude: The longitude of the location to get the weather for :param unit: The unit to use for the temperature (`celsius` or `fahrenheit`) :return: The JSON response to be fed back to the model """ - geolocator = Nominatim(user_agent="chatgpt-telegram-bot") - geoloc = geolocator.geocode(location) request = requests.get(f'https://api.open-meteo.com/v1/forecast' - f'?latitude={geoloc.latitude}' - f'&longitude={geoloc.longitude}' + f'?latitude={latitude}' + f'&longitude={longitude}' f'&daily=weathercode,temperature_2m_max,temperature_2m_min,precipitation_probability_mean,' f'&forecast_days=7' f'&timezone=auto' diff --git a/requirements.txt b/requirements.txt index 7018a13..1c523d3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,4 @@ tiktoken==0.4.0 openai==0.27.8 python-telegram-bot==20.3 requests~=2.31.0 -tenacity==8.2.2 -geopy~=2.3.0 \ No newline at end of file +tenacity==8.2.2 \ No newline at end of file