Spaces:
Running
Running
Update tool.py
Browse files
tool.py
CHANGED
@@ -4,10 +4,10 @@ from typing import Optional
|
|
4 |
class SimpleTool(Tool):
|
5 |
name = "get_travel_duration"
|
6 |
description = "Gets the travel time in car between two places."
|
7 |
-
inputs = {"start_location":{"type":"string","description":"the place from which you start your ride"},"destination_location":{"type":"string","description":"the place of arrival"},"
|
8 |
output_type = "string"
|
9 |
|
10 |
-
def forward(self, start_location: str, destination_location: str,
|
11 |
"""Gets the travel time in car between two places.
|
12 |
|
13 |
Args:
|
@@ -20,15 +20,14 @@ class SimpleTool(Tool):
|
|
20 |
|
21 |
gmaps = googlemaps.Client(os.getenv("GMAPS_API_KEY"))
|
22 |
|
23 |
-
if
|
24 |
-
|
25 |
-
monday = datetime(2025, 1, 6, 11, 0)
|
26 |
try:
|
27 |
directions_result = gmaps.directions(
|
28 |
start_location,
|
29 |
destination_location,
|
30 |
-
mode=
|
31 |
-
departure_time=
|
32 |
)
|
33 |
return directions_result[0]["legs"][0]["duration"]["text"]
|
34 |
except Exception as e:
|
|
|
4 |
class SimpleTool(Tool):
|
5 |
name = "get_travel_duration"
|
6 |
description = "Gets the travel time in car between two places."
|
7 |
+
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'.}}
|
8 |
output_type = "string"
|
9 |
|
10 |
+
def forward(self, start_location: str, destination_location: str, transportation: Optional[string] = None) -> str:
|
11 |
"""Gets the travel time in car between two places.
|
12 |
|
13 |
Args:
|
|
|
20 |
|
21 |
gmaps = googlemaps.Client(os.getenv("GMAPS_API_KEY"))
|
22 |
|
23 |
+
if transportation is None:
|
24 |
+
transportation = "transit"
|
|
|
25 |
try:
|
26 |
directions_result = gmaps.directions(
|
27 |
start_location,
|
28 |
destination_location,
|
29 |
+
mode=transportation,
|
30 |
+
departure_time=datetime(2025, 1, 6, 11, 0), # Start on a Monday morning
|
31 |
)
|
32 |
return directions_result[0]["legs"][0]["duration"]["text"]
|
33 |
except Exception as e:
|