Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,27 +9,33 @@ 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(arg1:str, arg2:int)-> str:
|
13 |
-
|
14 |
-
"""A tool that translates simple English words to French or Spanish.
|
15 |
Args:
|
16 |
-
arg1:
|
17 |
arg2: Language choice (0 = French, 1 = Spanish).
|
18 |
"""
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
}
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
|
35 |
@tool
|
@@ -69,7 +75,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
69 |
|
70 |
agent = CodeAgent(
|
71 |
model=model,
|
72 |
-
tools=[final_answer,
|
73 |
max_steps=6,
|
74 |
verbosity_level=1,
|
75 |
grammar=None,
|
|
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
+
def my_custom_tool(arg1: str, arg2: int) -> str:
|
13 |
+
"""A tool that fetches the current time in a timezone and adds a greeting in French or Spanish.
|
|
|
14 |
Args:
|
15 |
+
arg1: A string representing a valid timezone (e.g., 'America/New_York').
|
16 |
arg2: Language choice (0 = French, 1 = Spanish).
|
17 |
"""
|
18 |
+
import datetime
|
19 |
+
import pytz
|
20 |
+
|
21 |
+
# 定義多語言問候語
|
22 |
+
greetings = {
|
23 |
+
0: "Bonjour, l'heure actuelle à {timezone} est : {time}", # French
|
24 |
+
1: "Hola, la hora actual en {timezone} es : {time}" # Spanish
|
25 |
}
|
26 |
+
|
27 |
+
try:
|
28 |
+
# 創建時區對象並獲取當前時間
|
29 |
+
tz = pytz.timezone(arg1)
|
30 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
31 |
+
|
32 |
+
# 根據語言選擇問候語
|
33 |
+
if arg2 in greetings:
|
34 |
+
return greetings[arg2].format(timezone=arg1, time=local_time)
|
35 |
+
else:
|
36 |
+
return "Error: Use 0 for French or 1 for Spanish."
|
37 |
+
except Exception as e:
|
38 |
+
return f"Error fetching time for timezone '{arg1}': {str(e)}"
|
39 |
|
40 |
|
41 |
@tool
|
|
|
75 |
|
76 |
agent = CodeAgent(
|
77 |
model=model,
|
78 |
+
tools=[final_answer, my_custom_tool], ## add your tools here (don't remove final answer)
|
79 |
max_steps=6,
|
80 |
verbosity_level=1,
|
81 |
grammar=None,
|