create get_temp tool
Browse files
app.py
CHANGED
|
@@ -18,6 +18,22 @@ 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 |
+
|
| 22 |
+
@tool
|
| 23 |
+
def get_temperature(location: str) -> str:
|
| 24 |
+
"""A tool that fetches the current temperature in a specified location.
|
| 25 |
+
Args:
|
| 26 |
+
location: The name of the city or place (e.g., 'New York').
|
| 27 |
+
"""
|
| 28 |
+
try:
|
| 29 |
+
response = requests.get(f'https://wttr.in/{location}?format=%t')
|
| 30 |
+
if response.status_code == 200:
|
| 31 |
+
return f"The current temperature in {location} is {response.text}"
|
| 32 |
+
else:
|
| 33 |
+
return "Failed to retrieve temperature. Please check the location name."
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return f"Error fetching temperature for '{location}': {str(e)}"
|
| 36 |
+
|
| 37 |
@tool
|
| 38 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 39 |
"""A tool that fetches the current local time in a specified timezone.
|