MedHakim commited on
Commit
19cbc41
·
verified ·
1 Parent(s): 76f08e2

Update app.py

Browse files

Dev: distance calculator tool

Files changed (1) hide show
  1. app.py +23 -0
app.py CHANGED
@@ -18,6 +18,29 @@ 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_distance_between_two_locations_in_km(location1_str:str, location2_str:str)-> float: #it's import to specify the return type
23
+ #Keep this format for the description / args / args description but feel free to modify the tool
24
+ """
25
+ Calculate the distance in kilometers between two locations given as strings.
26
+
27
+ Args:
28
+ location1_str (str): Name or address of the first location.
29
+ location2_str (str): Name or address of the second location.
30
+
31
+ Returns:
32
+ float: Distance in kilometers.
33
+ """
34
+ geolocator = Photon(user_agent="geoapiExercises")
35
+ loc1 = geolocator.geocode(location1_str)
36
+ loc2 = geolocator.geocode(location2_str)
37
+ if not loc1 or not loc2:
38
+ #raise ValueError("Could not geocode one or both locations.")
39
+ return f"Could not geocode one or both locations. : {str(e)}"
40
+ coords_1 = (loc1.latitude, loc1.longitude)
41
+ coords_2 = (loc2.latitude, loc2.longitude)
42
+ return f"The distance between {location1_str} and {location2_str} is: {geodesic(coords_1, coords_2).kilometers}"
43
+
44
  @tool
45
  def get_current_time_in_timezone(timezone: str) -> str:
46
  """A tool that fetches the current local time in a specified timezone.