Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,15 +9,26 @@ 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 |
-
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""
|
| 15 |
Args:
|
| 16 |
-
arg1:
|
| 17 |
-
arg2: the
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
| 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.
|
|
@@ -55,7 +66,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[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 my_custom_tool(arg1: str, arg2: int) -> str: # it's important to specify the return type
|
| 13 |
+
# Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
+
"""Convert the current time in a given timezone by applying an hour offset.
|
| 15 |
Args:
|
| 16 |
+
arg1: The source timezone name (e.g., 'Europe/Paris')
|
| 17 |
+
arg2: The number of hours to offset the time (positive or negative)
|
| 18 |
"""
|
| 19 |
+
import datetime
|
| 20 |
+
import pytz
|
| 21 |
|
| 22 |
+
try:
|
| 23 |
+
source_tz = pytz.timezone(arg1)
|
| 24 |
+
now_in_source = datetime.datetime.now(source_tz)
|
| 25 |
+
shifted_time = now_in_source + datetime.timedelta(hours=arg2)
|
| 26 |
+
return (
|
| 27 |
+
f"Current time in {arg1}: {now_in_source.strftime('%Y-%m-%d %H:%M:%S')}\n"
|
| 28 |
+
f"Time after applying offset ({arg2}h): {shifted_time.strftime('%Y-%m-%d %H:%M:%S')}"
|
| 29 |
+
)
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return f"Error: {e}"
|
| 32 |
@tool
|
| 33 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 34 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 66 |
|
| 67 |
agent = CodeAgent(
|
| 68 |
model=model,
|
| 69 |
+
tools=[final_answer, my_custom_tool,get_current_time_in_timezone] ## add your tools here (don't remove final answer)
|
| 70 |
max_steps=6,
|
| 71 |
verbosity_level=1,
|
| 72 |
grammar=None,
|