Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,14 +22,28 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 22 |
@tool
|
| 23 |
def get_weather(location: str) -> dict:
|
| 24 |
"""
|
| 25 |
-
|
| 26 |
|
| 27 |
Parameters:
|
| 28 |
-
location (str): The location for which to fetch weather data (e.g.,
|
| 29 |
|
| 30 |
Returns:
|
| 31 |
-
dict: A dictionary containing weather information
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
"""
|
|
|
|
| 33 |
# Format the location for URL (e.g., "New York" -> "new-york")
|
| 34 |
location = location.replace(" ", "-").lower()
|
| 35 |
|
|
@@ -57,7 +71,6 @@ def get_weather(location: str) -> dict:
|
|
| 57 |
except Exception as e:
|
| 58 |
return {"error": f"An error occurred: {e}"}
|
| 59 |
|
| 60 |
-
|
| 61 |
@tool
|
| 62 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 63 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 22 |
@tool
|
| 23 |
def get_weather(location: str) -> dict:
|
| 24 |
"""
|
| 25 |
+
Scrapes the weather information for a given location from a weather website.
|
| 26 |
|
| 27 |
Parameters:
|
| 28 |
+
location (str): The name of the location for which to fetch the weather data (e.g., "New York", "London").
|
| 29 |
|
| 30 |
Returns:
|
| 31 |
+
dict: A dictionary containing weather information such as temperature and weather description,
|
| 32 |
+
or an error message if something goes wrong. The keys of the dictionary will include:
|
| 33 |
+
- 'temperature': The current temperature in the location.
|
| 34 |
+
- 'description': A short text describing the weather condition.
|
| 35 |
+
- 'location': The location for which the weather was fetched.
|
| 36 |
+
If an error occurs, the dictionary will include an 'error' key with the error message.
|
| 37 |
+
|
| 38 |
+
Example:
|
| 39 |
+
>>> get_weather("New York")
|
| 40 |
+
{'temperature': '18°C', 'description': 'Partly cloudy', 'location': 'new-york'}
|
| 41 |
+
|
| 42 |
+
Note:
|
| 43 |
+
This function relies on web scraping and the structure of the website may change over time.
|
| 44 |
+
Always check the legality of scraping a particular website before use.
|
| 45 |
"""
|
| 46 |
+
|
| 47 |
# Format the location for URL (e.g., "New York" -> "new-york")
|
| 48 |
location = location.replace(" ", "-").lower()
|
| 49 |
|
|
|
|
| 71 |
except Exception as e:
|
| 72 |
return {"error": f"An error occurred: {e}"}
|
| 73 |
|
|
|
|
| 74 |
@tool
|
| 75 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 76 |
"""A tool that fetches the current local time in a specified timezone.
|