m-ric HF Staff commited on
Commit
bcc880b
·
verified ·
1 Parent(s): 9d64508

Update tool.py

Browse files
Files changed (1) hide show
  1. tool.py +6 -7
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"},"departure_time":{"type":"integer","nullable":True,"description":"the departure time, provide only a `datetime.datetime` if you want to specify this"}}
8
  output_type = "string"
9
 
10
- def forward(self, start_location: str, destination_location: str, departure_time: Optional[int] = None) -> 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 departure_time is None:
24
- from datetime import datetime
25
- monday = datetime(2025, 1, 6, 11, 0)
26
  try:
27
  directions_result = gmaps.directions(
28
  start_location,
29
  destination_location,
30
- mode="transit",
31
- departure_time=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: