Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,27 @@ 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(
|
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:
|
@@ -49,13 +62,14 @@ custom_role_conversions=None,
|
|
49 |
|
50 |
# Import tool from Hub
|
51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
|
52 |
|
53 |
with open("prompts.yaml", 'r') as stream:
|
54 |
prompt_templates = yaml.safe_load(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 my_custom_tool(start_date: str, end_date: str) -> str:
|
13 |
+
"""A tool that calculates the number of days between two dates.
|
|
|
14 |
Args:
|
15 |
+
start_date: The start date in the format 'YYYY-MM-DD'.
|
16 |
+
end_date: The end date in the format 'YYYY-MM-DD'.
|
17 |
"""
|
18 |
+
try:
|
19 |
+
# Parse the input dates
|
20 |
+
start = datetime.datetime.strptime(start_date, "%Y-%m-%d")
|
21 |
+
end = datetime.datetime.strptime(end_date, "%Y-%m-%d")
|
22 |
+
|
23 |
+
# Calculate the difference in days
|
24 |
+
delta = (end - start).days
|
25 |
+
|
26 |
+
if delta < 0:
|
27 |
+
return "The end date must be after the start date."
|
28 |
+
|
29 |
+
return f"There are {delta} days between {start_date} and {end_date}."
|
30 |
+
|
31 |
+
except ValueError:
|
32 |
+
return "Invalid date format. Please use 'YYYY-MM-DD'."
|
33 |
|
34 |
@tool
|
35 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
62 |
|
63 |
# Import tool from Hub
|
64 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
65 |
+
search_tool = DuckDuckGoSearchTool()
|
66 |
|
67 |
with open("prompts.yaml", 'r') as stream:
|
68 |
prompt_templates = yaml.safe_load(stream)
|
69 |
|
70 |
agent = CodeAgent(
|
71 |
model=model,
|
72 |
+
tools=[final_answer, search_tool, image_generation_tool, get_current_time_in_timezone, my_custom_tool], ## add your tools here (don't remove final answer)
|
73 |
max_steps=6,
|
74 |
verbosity_level=1,
|
75 |
grammar=None,
|