diff --git a/backend/app/tool/__init__.py b/backend/app/tool/__init__.py index 33652e6..527055e 100644 --- a/backend/app/tool/__init__.py +++ b/backend/app/tool/__init__.py @@ -1,9 +1,11 @@ from .searchOnlineTool import fetch_web_page, search_duckduckgo from .getStopsTool import get_all_stop_times +from .googleMapsTool import google_maps_navigation FUNCTION_MAPPING = { "fetch_web_page": fetch_web_page, "search_duckduckgo": search_duckduckgo, - "get_all_stop_times": get_all_stop_times + "get_all_stop_times": get_all_stop_times, + "google_maps_navigation": google_maps_navigation } diff --git a/backend/app/tool/googleMapsTool.py b/backend/app/tool/googleMapsTool.py new file mode 100644 index 0000000..55185c8 --- /dev/null +++ b/backend/app/tool/googleMapsTool.py @@ -0,0 +1,63 @@ +from app.tool.gtfs.data_loader import GTFS_data +import googlemaps +import json + +api_key = "YOUR_GOOGLE_MAPS_API_KEY" + +def google_maps_navigation(start_longitude, start_latitude, destination_longitude, destination_latitude, api_key=api_key): + """ + Utilizes the Google Maps API to return the full navigation path given the longitude and latitude of the start and destination points. + + Parameters: + - start_longitude (float): The longitude of the starting point. + - start_latitude (float): The latitude of the starting point. + - end_longitude (float): The longitude of the destination point. + - end_latitude (float): The latitude of the destination point. + - api_key (str): The API key for accessing Google Maps services. + + Returns: + - dict: The navigation path details. + """ + gmaps = googlemaps.Client(key=api_key) + + # Request directions via driving mode + directions_result = gmaps.directions( + (start_latitude, start_longitude), + (destination_latitude, destination_longitude), + mode="driving" + ) + + if not directions_result: + return {"error": "No route found"} + + # Extract the relevant information from the directions result + route = directions_result[0] + legs = route.get("legs", []) + steps = [] + + for leg in legs: + for step in leg.get("steps", []): + steps.append({ + "start_location": step["start_location"], + "end_location": step["end_location"], + "instructions": step["html_instructions"], + "distance": step["distance"]["text"], + "duration": step["duration"]["text"] + }) + + return { + "start_location": {"lat": start_latitude, "lng": start_longitude}, + "end_location": {"lat": destination_latitude, "lng": destination_longitude}, + "steps": steps + } + +# Example usage +""" if __name__ == "__main__": + api_key = "YOUR_GOOGLE_MAPS_API_KEY" + start_longitude = -122.084 + start_latitude = 37.422 + end_longitude = -122.084 + end_latitude = 37.422 + navigation_path = google_maps_navigation(start_longitude, start_latitude, end_longitude, end_latitude, api_key) + print(json.dumps(navigation_path, indent=2)) """ + diff --git a/backend/storage/tool/tool_register.json b/backend/storage/tool/tool_register.json index b6d53fe..b3b25da 100644 --- a/backend/storage/tool/tool_register.json +++ b/backend/storage/tool/tool_register.json @@ -60,5 +60,39 @@ ] } } + }, + { + "type": "function", + "function": { + "name": "google_maps_navigation", + "description": "Utilizes the Google Maps API to return the full navigation path given the longitude and latitude of the start and destination points.", + "parameters": { + "type": "object", + "properties": { + "start_longitude": { + "type": "number", + "description": "The longitude of the starting point." + }, + "start_latitude": { + "type": "number", + "description": "The latitude of the starting point." + }, + "destination_longitude": { + "type": "number", + "description": "The longitude of the destination point." + }, + "destination_latitude": { + "type": "number", + "description": "The latitude of the destination point." + } + }, + "required": [ + "start_longitude", + "start_latitude", + "destination_longitude", + "destination_latitude" + ] + } + } } ] \ No newline at end of file diff --git a/backend/storage/tool/tool_register_TODO.json b/backend/storage/tool/tool_register_TODO.json index 27f5cd3..8821984 100644 --- a/backend/storage/tool/tool_register_TODO.json +++ b/backend/storage/tool/tool_register_TODO.json @@ -17,5 +17,34 @@ ] } } + }, + { + "type": "function", + "function": { + "name": "local_traffic_prediction", + "description": "Predicts traffic patterns and potential congestion using locally stored historical and real-time traffic data.", + "parameters": { + "type": "object", + "properties": { + "prediction_window": { + "type": "integer", + "description": "The time window (in minutes or hours) for which the model should predict future traffic conditions." + }, + "update_interval": { + "type": "integer", + "description": "The interval at which real-time data should update predictions." + }, + "region": { + "type": "string", + "description": "The region or area within the city for which traffic predictions should be made." + } + }, + "required": [ + "prediction_window", + "update_interval", + "region" + ] + } + } } ] \ No newline at end of file