Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,58 @@ 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
|
13 |
-
|
14 |
-
"""A tool that does nothing yet
|
15 |
Args:
|
16 |
-
|
17 |
-
arg2: the second argument
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -55,7 +99,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
+
def weather_check(city: str) -> str:
|
13 |
+
"""获取指定城市的实时天气并生成艺术化展示
|
|
|
14 |
Args:
|
15 |
+
city: 城市名称(支持中英文,如'北京'或'New York')
|
|
|
16 |
"""
|
17 |
+
# 天气图标映射库
|
18 |
+
weather_art = {
|
19 |
+
"晴": r'''
|
20 |
+
\ / ☀️
|
21 |
+
.-"""-.
|
22 |
+
_/_______\_
|
23 |
+
(___________)
|
24 |
+
''',
|
25 |
+
"雨": r'''
|
26 |
+
´¯`•.¸¸.•´¯`
|
27 |
+
(´•̥̥̥o•̥̥̥`).•´¯`•.☔️
|
28 |
+
`·.¸( •̥̥̥o•̥̥̥ )
|
29 |
+
''',
|
30 |
+
"云": r'''
|
31 |
+
.-~~~-.
|
32 |
+
/ ☁️ \
|
33 |
+
; ;
|
34 |
+
| |
|
35 |
+
\ /
|
36 |
+
`~~~~~`
|
37 |
+
'''
|
38 |
+
}
|
39 |
+
|
40 |
+
try:
|
41 |
+
response = requests.get(
|
42 |
+
f"https://api.open-meteo.com/v1/forecast?city={city}¤t_weather=true"
|
43 |
+
)
|
44 |
+
data = response.json()
|
45 |
+
condition = data["current"]["weathercode"]
|
46 |
+
|
47 |
+
# 转换天气代码为文字描述
|
48 |
+
weather_map = {
|
49 |
+
0: "晴", 1: "晴", 2: "云", 3: "云",
|
50 |
+
45: "雾", 48: "雾", 51: "雨", 61: "雨"
|
51 |
+
}
|
52 |
+
status = weather_map.get(condition, "未知")
|
53 |
+
|
54 |
+
# 生成艺术报告
|
55 |
+
art = weather_art.get(status, r'''
|
56 |
+
╱╲╱╲
|
57 |
+
◖_◗◖_◗
|
58 |
+
‾‾‾‾‾‾
|
59 |
+
''')
|
60 |
+
return f"{city}当前天气:{status}\n{art}"
|
61 |
+
|
62 |
+
except Exception as e:
|
63 |
+
return f"天气查询失败:{str(e)}"
|
64 |
|
65 |
@tool
|
66 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
99 |
|
100 |
agent = CodeAgent(
|
101 |
model=model,
|
102 |
+
tools=[final_answer, weather_check], ## add your tools here (don't remove final answer)
|
103 |
max_steps=6,
|
104 |
verbosity_level=1,
|
105 |
grammar=None,
|