LucMarcelPellinger commited on
Commit
1a40ad6
·
verified ·
1 Parent(s): 22a1e30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -23,14 +23,20 @@ def my_custom_tool(arg1:int, arg2:int)-> str: #it's import to specify the return
23
  return f"the result is {a}"
24
 
25
  @tool
26
- def todays_useless_fact(date: datetime | str) -> str:
27
  """Fetches today's useless fact from an external public API.
28
  Args:
29
  date: the datetime value for the specified time zone retrieved from get_current_time_in_timezone.
30
  """
31
  try:
32
  # Format date as YYYY-MM-DD (API only supports "today" or "random")
33
- formatted_date = date.strftime("%Y-%m-%d")
 
 
 
 
 
 
34
 
35
  # API doesn't actually support querying by date, so we just show today's
36
  response = requests.get("https://uselessfacts.jsph.pl/api/v2/facts/today")
 
23
  return f"the result is {a}"
24
 
25
  @tool
26
+ def todays_useless_fact(input_time: datetime | str) -> str:
27
  """Fetches today's useless fact from an external public API.
28
  Args:
29
  date: the datetime value for the specified time zone retrieved from get_current_time_in_timezone.
30
  """
31
  try:
32
  # Format date as YYYY-MM-DD (API only supports "today" or "random")
33
+ if isinstance(input_time, str):
34
+ try:
35
+ input_time = datetime.fromisoformat(input_time)
36
+ except ValueError:
37
+ return "Invalid datetime format. Please use ISO format: YYYY-MM-DDTHH:MM:SS"
38
+
39
+ formatted_date = input_time.strftime("%Y-%m-%d")
40
 
41
  # API doesn't actually support querying by date, so we just show today's
42
  response = requests.get("https://uselessfacts.jsph.pl/api/v2/facts/today")