from geopy.geocoders import Nominatim import pandas as pd import requests import uuid
# gets latitude and longitude defget_lat_long(location): geolocator = Nominatim(user_agent="my_application_" + str(uuid.uuid4())) location = geolocator.geocode(location) return (location.latitude, location.longitude)
# gets weather data for the enxt five days - returns a dataframe defget_weather(location_response, location): api_key = YOUR_OPEN_WEATHER_MAP_API_KEY # Replace with your API key from Open Weather Map base_url = "https://api.openweathermap.org/data/2.5/forecast" params = { 'lat': location_response[0], # latitude 'lon': location_response[1], # longitude 'appid': api_key, 'units': 'metric'# change 'metric' to 'imperial' for Fahrenheit } response = requests.get(base_url, params=params) weather_data = response.json() df = pd.json_normalize(weather_data['list']).drop(columns='weather') df['location'] = location return df
defparse_location(query): # OpenAI function calling function_call = [ { "name": "get_lat_long", "description": "Takes the location as an argument. Returns a tuple (latiude, longitude)", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": '''Do not answer the question. Only respond with the location, or the location of the landmark/tourist attraction mentioned. Location must be in the form City name, state code (only for the US) and country code divided by comma. Please use ISO 3166 country codes.''' } }, "required": ["location"] } } ] # Open AI API Call openai.api_key = YOUR_OPEN_AI_API_KEY # Replace this with your openAI API key
query = "What's the best day to visit the Eiffel Tower for the best view of the city?" query_1 = f"{query} Return an explanation alongside your response, and a description of the relevant weather conditions"