TheBumblingBaboon commited on
Commit
1139965
·
verified ·
1 Parent(s): 16cc3b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py CHANGED
@@ -18,6 +18,37 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def get_travel_duration(start_location: str, destination_location: str, transportation_mode: Optional[str] = None) -> str:
23
+ """Gets the travel time between two places.
24
+
25
+ Args:
26
+ start_location: the place from which you start your ride
27
+ destination_location: the place of arrival
28
+ transportation_mode: The transportation mode, in 'driving', 'walking', 'bicycling', or 'transit'. Defaults to 'driving'.
29
+ """
30
+ import os # All imports are placed within the function, to allow for sharing to Hub.
31
+ import googlemaps
32
+ from datetime import datetime
33
+
34
+ gmaps = googlemaps.Client(os.getenv("GMAPS_API_KEY"))
35
+
36
+ if transportation_mode is None:
37
+ transportation_mode = "driving"
38
+ try:
39
+ directions_result = gmaps.directions(
40
+ start_location,
41
+ destination_location,
42
+ mode=transportation_mode,
43
+ departure_time=datetime(2025, 6, 6, 11, 0), # At 11, date far in the future
44
+ )
45
+ if len(directions_result) == 0:
46
+ return "No way found between these places with the required transportation mode."
47
+ return directions_result[0]["legs"][0]["duration"]["text"]
48
+ except Exception as e:
49
+ print(e)
50
+ return e
51
+
52
  @tool
53
  def get_current_time_in_timezone(timezone: str) -> str:
54
  """A tool that fetches the current local time in a specified timezone.