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