Spaces:
Sleeping
Sleeping
Added tool to convert localtime to unix
Browse files
app.py
CHANGED
|
@@ -9,14 +9,24 @@ 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 |
-
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +65,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 convert_local_time_to_unixtime(localtime: str) -> str:
|
| 13 |
+
"""A tool that converts local time into a unix timestamp.
|
|
|
|
| 14 |
Args:
|
| 15 |
+
localtime: A string representing the local time in 'YYYY-mm-dd HH:MM:SS', example: 2026-12-31 12:34:56'.
|
| 16 |
+
Returns:
|
| 17 |
+
A string representing the unix timestamp.
|
| 18 |
"""
|
| 19 |
+
|
| 20 |
+
# Convert the local time string to a datetime object
|
| 21 |
+
try:
|
| 22 |
+
dt_object = datetime.datetime.strptime(localtime,("%Y-%m-%d %H:%M:%S"))
|
| 23 |
+
# Convert the datetime object to a unix timestamp
|
| 24 |
+
unix_timestamp = int(dt_object.timestamp())
|
| 25 |
+
except:
|
| 26 |
+
return f"Invalid local time format."
|
| 27 |
+
|
| 28 |
+
# Return
|
| 29 |
+
return str(unix_timestamp)
|
| 30 |
|
| 31 |
@tool
|
| 32 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 65 |
|
| 66 |
agent = CodeAgent(
|
| 67 |
model=model,
|
| 68 |
+
tools=[final_answer, get_current_time_in_timezone, convert_local_time_to_unixtime], ## add your tools here (don't remove final answer)
|
| 69 |
max_steps=6,
|
| 70 |
verbosity_level=1,
|
| 71 |
grammar=None,
|