Spaces:
Sleeping
Sleeping
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)." | |
) | |
] |