howi96 commited on
Commit
8476612
·
verified ·
1 Parent(s): 8c5c24b

Updates app.py

Browse files

Added get_season_from_local_time tool and updated tools parameter in agents

Files changed (1) hide show
  1. app.py +36 -8
app.py CHANGED
@@ -9,14 +9,42 @@ 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:
@@ -48,14 +76,14 @@ custom_role_conversions=None,
48
 
49
 
50
  # Import tool from Hub
51
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
52
 
53
  with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(stream)
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def get_season_from_local_time(local_time: str) -> str:
13
+ """Determines the season (Winter, Spring, Summer, Autumn) based on a local datetime string.
14
+
15
  Args:
16
+ local_time: A string representing local time in the format "%Y-%m-%d %H:%M:%S".
17
+
18
+ Returns:
19
+ A string indicating the season in the Northern Hemisphere.
20
+
21
+ Notes:
22
+ - Uses astronomical seasons:
23
+ * Spring: March 20 – June 20
24
+ * Summer: June 21 – September 22
25
+ * Autumn: September 23 – December 20
26
+ * Winter: December 21 – March 19 (next year)
27
+ - Assumes Northern Hemisphere.
28
  """
29
+ try:
30
+ date = datetime.datetime.strptime(local_time, "%Y-%m-%d %H:%M:%S")
31
+ year = date.year
32
+
33
+ spring_start = datetime(year, 3, 20)
34
+ summer_start = datetime(year, 6, 21)
35
+ autumn_start = datetime(year, 9, 23)
36
+ winter_start = datetime(year, 12, 21)
37
+
38
+ if date >= winter_start or date < spring_start:
39
+ return "Winter"
40
+ elif spring_start <= date < summer_start:
41
+ return "Spring"
42
+ elif summer_start <= date < autumn_start:
43
+ return "Summer"
44
+ else:
45
+ return "Autumn"
46
+ except Exception as e:
47
+ return f"Error determining season from '{local_time}': {str(e)}"
48
 
49
  @tool
50
  def get_current_time_in_timezone(timezone: str) -> str:
 
76
 
77
 
78
  # Import tool from Hub
79
+ #image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
80
 
81
  with open("prompts.yaml", 'r') as stream:
82
  prompt_templates = yaml.safe_load(stream)
83
 
84
  agent = CodeAgent(
85
  model=model,
86
+ tools=[get_season_from_local_time,get_current_time_in_timezone,final_answer], ## add your tools here (don't remove final answer)
87
  max_steps=6,
88
  verbosity_level=1,
89
  grammar=None,