Spaces:
Sleeping
Sleeping
修改了天气工具
Browse files
app.py
CHANGED
|
@@ -9,10 +9,11 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def my_custom_tool(city_lat:float, city_lon:float)-> str: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
"""A tool for querying the weather of a specified city.
|
| 15 |
Args:
|
|
|
|
| 16 |
city_lat: the city latitude
|
| 17 |
city_lon: the city longitude
|
| 18 |
"""
|
|
@@ -21,11 +22,11 @@ def my_custom_tool(city_lat:float, city_lon:float)-> str: #it's import to specif
|
|
| 21 |
response = requests.get(url)
|
| 22 |
data = response.json()
|
| 23 |
|
| 24 |
-
|
| 25 |
weather = data["current_weather"]
|
| 26 |
-
return f"
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
@tool
|
| 31 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def my_custom_tool(city:str,city_lat:float, city_lon:float)-> str: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
"""A tool for querying the weather of a specified city.
|
| 15 |
Args:
|
| 16 |
+
city: the city name
|
| 17 |
city_lat: the city latitude
|
| 18 |
city_lon: the city longitude
|
| 19 |
"""
|
|
|
|
| 22 |
response = requests.get(url)
|
| 23 |
data = response.json()
|
| 24 |
|
| 25 |
+
try:
|
| 26 |
weather = data["current_weather"]
|
| 27 |
+
return f"{city}的天气如下:温度: {weather['temperature']}°C, 风速: {weather['windspeed']} km/h, 天气情况: {weather['weathercode']}"
|
| 28 |
+
except Exception as e:
|
| 29 |
+
return "无法获取天气数据"
|
| 30 |
|
| 31 |
@tool
|
| 32 |
def get_current_time_in_timezone(timezone: str) -> str:
|