MHamdan commited on
Commit
77b0ccb
·
verified ·
1 Parent(s): 841e77b

Upload tool

Browse files
Files changed (1) hide show
  1. tool.py +45 -16
tool.py CHANGED
@@ -4,7 +4,7 @@ from typing import Any, Optional
4
  class SimpleTool(Tool):
5
  name = "calculate_journey_metrics"
6
  description = "Calculates journey metrics including distance and time."
7
- inputs = {"start_location":{"type":"string","description":"The starting point of the journey."},"destination_location":{"type":"string","description":"The endpoint of the journey."},"transportation_mode":{"type":"string","nullable":True,"description":"Mode of transport ('driving', 'walking', 'bicycling', or 'transit'). Defaults to 'driving'."}}
8
  output_type = "string"
9
 
10
  def forward(self, start_location: str, destination_location: str, transportation_mode: Optional[str] = None) -> str:
@@ -13,7 +13,7 @@ class SimpleTool(Tool):
13
  Args:
14
  start_location: The starting point of the journey.
15
  destination_location: The endpoint of the journey.
16
- transportation_mode: Mode of transport ('driving', 'walking', 'bicycling', or 'transit').
17
  Defaults to 'driving'.
18
 
19
  Returns:
@@ -39,31 +39,60 @@ class SimpleTool(Tool):
39
  (end.latitude, end.longitude)
40
  ).kilometers
41
 
42
- # Define speeds (km/h)
43
  speeds = {
44
- 'driving': 60,
45
- 'walking': 5,
46
- 'bicycling': 15,
47
- 'transit': 30
 
 
 
 
 
48
  }
49
 
50
- # Get speed for mode
51
- speed = speeds.get(transportation_mode, speeds['driving'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  # Calculate time
54
- hours = distance_km / speed
 
55
 
56
  # Format time string
57
- if hours < 1:
58
- time_str = f"{int(hours * 60)} minutes"
59
- elif hours < 24:
60
- hrs = int(hours)
61
- mins = int((hours - hrs) * 60)
62
  time_str = f"{hrs} hours and {mins} minutes"
63
  else:
64
- days = hours / 24
65
  time_str = f"{days:.1f} days"
66
 
 
 
 
 
 
 
 
 
 
67
  return (
68
  f"Journey metrics:\n"
69
  f"Distance: {distance_km:.1f} kilometers\n"
 
4
  class SimpleTool(Tool):
5
  name = "calculate_journey_metrics"
6
  description = "Calculates journey metrics including distance and time."
7
+ inputs = {"start_location":{"type":"string","description":"The starting point of the journey."},"destination_location":{"type":"string","description":"The endpoint of the journey."},"transportation_mode":{"type":"string","nullable":True,"description":"Mode of transport ('driving', 'walking', 'bicycling', 'transit', or 'plane'). Defaults to 'driving'."}}
8
  output_type = "string"
9
 
10
  def forward(self, start_location: str, destination_location: str, transportation_mode: Optional[str] = None) -> str:
 
13
  Args:
14
  start_location: The starting point of the journey.
15
  destination_location: The endpoint of the journey.
16
+ transportation_mode: Mode of transport ('driving', 'walking', 'bicycling', 'transit', or 'plane').
17
  Defaults to 'driving'.
18
 
19
  Returns:
 
39
  (end.latitude, end.longitude)
40
  ).kilometers
41
 
42
+ # Define speeds (km/h) with more realistic values
43
  speeds = {
44
+ 'driving': {'urban': 30, 'highway': 100, 'average': 80},
45
+ 'walking': {'average': 5},
46
+ 'bicycling': {'casual': 12, 'average': 20},
47
+ 'transit': {'urban': 30, 'intercity': 60},
48
+ 'plane': {
49
+ 'short_haul': 500, # Including taxiing, takeoff, landing
50
+ 'medium_haul': 700,
51
+ 'long_haul': 800
52
+ }
53
  }
54
 
55
+ # Get appropriate speed based on distance and mode
56
+ if transportation_mode == 'plane':
57
+ if distance_km < 500:
58
+ speed = speeds['plane']['short_haul']
59
+ elif distance_km < 3000:
60
+ speed = speeds['plane']['medium_haul']
61
+ else:
62
+ speed = speeds['plane']['long_haul']
63
+
64
+ # Add airport procedures time (hours)
65
+ additional_time = 2 # 2 hours for airport procedures
66
+ else:
67
+ # Default to driving if mode not specified
68
+ mode = transportation_mode or 'driving'
69
+ speed = speeds.get(mode, speeds['driving'])['average']
70
+ additional_time = 0
71
 
72
  # Calculate time
73
+ travel_time = distance_km / speed
74
+ total_hours = travel_time + additional_time
75
 
76
  # Format time string
77
+ if total_hours < 1:
78
+ time_str = f"{int(total_hours * 60)} minutes"
79
+ elif total_hours < 24:
80
+ hrs = int(total_hours)
81
+ mins = int((total_hours - hrs) * 60)
82
  time_str = f"{hrs} hours and {mins} minutes"
83
  else:
84
+ days = total_hours / 24
85
  time_str = f"{days:.1f} days"
86
 
87
+ # Additional information for plane travel
88
+ if transportation_mode == 'plane':
89
+ return (
90
+ f"Journey metrics:\n"
91
+ f"Distance: {distance_km:.1f} kilometers\n"
92
+ f"Flight time: {int(travel_time * 60)} minutes\n"
93
+ f"Total estimated time (including airport procedures): {time_str}"
94
+ )
95
+
96
  return (
97
  f"Journey metrics:\n"
98
  f"Distance: {distance_km:.1f} kilometers\n"