ashkanhh commited on
Commit
3e3a832
·
verified ·
1 Parent(s): 73b510b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -7
app.py CHANGED
@@ -8,15 +8,39 @@ from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
 
 
 
 
 
 
 
 
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -55,7 +79,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
+ # @tool
12
+ # def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
+ # #Keep this format for the description / args / args description but feel free to modify the tool
14
+ # """A tool that does nothing yet
15
+ # Args:
16
+ # arg1: the first argument
17
+ # arg2: the second argument
18
+ # """
19
+ # return "What magic will you build ?"
20
  @tool
21
+ def add_days_to_date(arg1: str, arg2: int) -> str: # Or your chosen name
22
+ """Calculates a future or past date by adding a number of days (arg2) to a base date (arg1).
23
+ The base date (arg1) must be provided in 'YYYY-MM-DD' format.
24
+
25
  Args:
26
+ arg1 (str): The base date string in 'YYYY-MM-DD' format (e.g., '2024-07-15').
27
+ arg2 (int): The number of days to add. Positive for future, negative for past.
28
+ If 0, the original date is returned (after validation and reformatting).
29
+
30
+ Returns:
31
+ str: The resulting date string in 'YYYY-MM-DD' format, or an error message if arg1 is not a valid date format.
32
  """
33
+ base_date_str = arg1
34
+ days_to_offset = arg2
35
+ # ... rest of the implementation remains the same
36
+ try:
37
+ base_datetime_obj = datetime.datetime.strptime(base_date_str, "%Y-%m-%d")
38
+ new_datetime_obj = base_datetime_obj + datetime.timedelta(days=days_to_offset)
39
+ return new_datetime_obj.strftime("%Y-%m-%d")
40
+ except ValueError:
41
+ return f"Error: Invalid date format for '{base_date_str}'. Please use 'YYYY-MM-DD'."
42
+ except Exception as e:
43
+ return f"An unexpected error occurred while calculating the date: {str(e)}"
44
 
45
  @tool
46
  def get_current_time_in_timezone(timezone: str) -> str:
 
79
 
80
  agent = CodeAgent(
81
  model=model,
82
+ tools=[final_answer, get_current_time_in_timezone, add_days_to_date], ## add your tools here (don't remove final answer)
83
  max_steps=6,
84
  verbosity_level=1,
85
  grammar=None,