Spaces:
Sleeping
Sleeping
add new tool to convert units without using web search
Browse filesThe tool was deliberately not added to the list of tools to see whether the agent uses WebSearch or training data without this specification
app.py
CHANGED
|
@@ -38,6 +38,28 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 38 |
except Exception as e:
|
| 39 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
final_answer = FinalAnswerTool()
|
| 43 |
|
|
|
|
| 38 |
except Exception as e:
|
| 39 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 40 |
|
| 41 |
+
@tool
|
| 42 |
+
def convert_units(value: float, from_unit: str, to_unit: str) -> str:
|
| 43 |
+
"""Converts a value between common units (km/miles, kg/lbs, celsius/fahrenheit).
|
| 44 |
+
Args:
|
| 45 |
+
value: The numeric value to convert.
|
| 46 |
+
from_unit: The source unit (e.g. 'km', 'kg', 'celsius').
|
| 47 |
+
to_unit: The target unit (e.g. 'miles', 'lbs', 'fahrenheit').
|
| 48 |
+
"""
|
| 49 |
+
conversions = {
|
| 50 |
+
("km", "miles"): lambda x: x * 0.621371,
|
| 51 |
+
("miles", "km"): lambda x: x * 1.60934,
|
| 52 |
+
("kg", "lbs"): lambda x: x * 2.20462,
|
| 53 |
+
("lbs", "kg"): lambda x: x * 0.453592,
|
| 54 |
+
("celsius", "fahrenheit"): lambda x: x * 9/5 + 32,
|
| 55 |
+
("fahrenheit", "celsius"): lambda x: (x - 32) * 5/9,
|
| 56 |
+
}
|
| 57 |
+
key = (from_unit.lower(), to_unit.lower())
|
| 58 |
+
if key in conversions:
|
| 59 |
+
result = conversions[key](value)
|
| 60 |
+
return f"{value} {from_unit} = {result:.4f} {to_unit}"
|
| 61 |
+
return f"Conversion from '{from_unit}' to '{to_unit}' is not supported."
|
| 62 |
+
|
| 63 |
|
| 64 |
final_answer = FinalAnswerTool()
|
| 65 |
|