Spaces:
Running
Running
add tools
Browse files- create time_difference tool
- add tools to agent
app.py
CHANGED
@@ -18,6 +18,30 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
18 |
"""
|
19 |
return "What magic will you build ?"
|
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.
|
@@ -35,6 +59,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
35 |
|
36 |
|
37 |
final_answer = FinalAnswerTool()
|
|
|
38 |
|
39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
@@ -55,7 +80,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,
|
|
|
18 |
"""
|
19 |
return "What magic will you build ?"
|
20 |
|
21 |
+
@tool
|
22 |
+
def time_difference(time1: str, time2: str) -> str:
|
23 |
+
"""A tool that calculates the time difference between two timestamps.
|
24 |
+
|
25 |
+
Args:
|
26 |
+
time1: The first timestamp (format: YYYY-MM-DD HH:MM:SS)
|
27 |
+
time2: The second timestamp (format: YYYY-MM-DD HH:MM:SS)
|
28 |
+
|
29 |
+
Returns:
|
30 |
+
A string describing the time difference.
|
31 |
+
"""
|
32 |
+
try:
|
33 |
+
fmt = "%Y-%m-%d %H:%M:%S"
|
34 |
+
dt1 = datetime.datetime.strptime(time1, fmt)
|
35 |
+
dt2 = datetime.datetime.strptime(time2, fmt)
|
36 |
+
|
37 |
+
delta = abs(dt1 - dt2)
|
38 |
+
hours, remainder = divmod(delta.seconds, 3600)
|
39 |
+
minutes = remainder // 60
|
40 |
+
|
41 |
+
return f"The time difference is {delta.days} days, {hours} hours, and {minutes} minutes."
|
42 |
+
except ValueError:
|
43 |
+
return "Invalid date format. Please use 'YYYY-MM-DD HH:MM:SS'."
|
44 |
+
|
45 |
@tool
|
46 |
def get_current_time_in_timezone(timezone: str) -> str:
|
47 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
59 |
|
60 |
|
61 |
final_answer = FinalAnswerTool()
|
62 |
+
duck_duck_go_search = DuckDuckGoSearchTool()
|
63 |
|
64 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
65 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
80 |
|
81 |
agent = CodeAgent(
|
82 |
model=model,
|
83 |
+
tools=[final_answer, duck_duck_go_search, get_current_time_in_timezone(), time_difference()], ## add your tools here (don't remove final answer)
|
84 |
max_steps=6,
|
85 |
verbosity_level=1,
|
86 |
grammar=None,
|