Spaces:
Running
Running
File size: 1,598 Bytes
6e4eef0 c6aa194 6e4eef0 bcc880b 6e4eef0 bcc880b 6e4eef0 bcc880b 6351c15 bcc880b 6351c15 3494381 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
from smolagents import Tool
from typing import Optional
class SimpleTool(Tool):
name = "get_travel_duration"
description = "Gets the travel time in car between two places."
inputs = {"start_location":{"type":"string","description":"the place from which you start your ride"},"destination_location":{"type":"string","description":"the place of arrival"},"transportation":{"type":"string","nullable":True,"description":"The transportation type, in 'driving', 'walking', 'bicycling', or 'transit'.}}
output_type = "string"
def forward(self, start_location: str, destination_location: str, transportation: Optional[string] = None) -> str:
"""Gets the travel time in car between two places.
Args:
start_location: the place from which you start your ride
destination_location: the place of arrival
departure_time: the departure time, provide only a `datetime.datetime` if you want to specify this
"""
import googlemaps
import os
gmaps = googlemaps.Client(os.getenv("GMAPS_API_KEY"))
if transportation is None:
transportation = "transit"
try:
directions_result = gmaps.directions(
start_location,
destination_location,
mode=transportation,
departure_time=datetime(2025, 1, 6, 11, 0), # Start on a Monday morning
)
return directions_result[0]["legs"][0]["duration"]["text"]
except Exception as e:
print(e, directions_result)
return e |