Daniel Amendoeira commited on
Commit
714d637
·
verified ·
1 Parent(s): 766af75

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +35 -0
tools.py CHANGED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.tools import Tool
2
+ import datetime
3
+
4
+ def current_date(_):
5
+ return datetime.datetime.now().strftime("%Y-%m-%d")
6
+
7
+ def day_of_week(_):
8
+ return datetime.datetime.now().strftime("%A")
9
+
10
+ def days_until(date_str):
11
+ try:
12
+ future_date = datetime.datetime.strptime(date_str, "%Y-%m-%d")
13
+ today = datetime.datetime.now()
14
+ delta = future_date - today
15
+ return f"{delta.days} days until {date_str}"
16
+ except Exception as e:
17
+ return f"Error parsing date: {str(e)}"
18
+
19
+ datetime_tools = [
20
+ Tool(
21
+ name="current_date",
22
+ func=current_date,
23
+ description="Returns the current date in YYYY-MM-DD format."
24
+ ),
25
+ Tool(
26
+ name="current_day_of_week",
27
+ func=day_of_week,
28
+ description="Returns the current day of the week (e.g., Monday, Tuesday)."
29
+ ),
30
+ Tool(
31
+ name="days_until",
32
+ func=days_until,
33
+ description="Returns the number of days from today until a given date (input format: YYYY-MM-DD)."
34
+ )
35
+ ]