jborelo commited on
Commit
bc8e4e9
·
verified ·
1 Parent(s): 58bf90d

Add get_next_trains_krakow_to_warszawa tool

Browse files
Files changed (1) hide show
  1. app.py +53 -13
app.py CHANGED
@@ -5,7 +5,6 @@ import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  from typing import List
8
-
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
@@ -33,12 +32,57 @@ def get_friends_names(name:str, maxnb: int)-> List[str]: #it's import to specify
33
  return "Piotrek Jan Pawel Ania".split()[:maxnb]
34
  return []
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  @tool
38
- def get_current_time_in_timezone(timezone: str) -> str:
39
- """A tool that fetches the current local time in a specified timezone.
40
  Args:
41
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
42
  """
43
  try:
44
  # Create timezone object
@@ -49,20 +93,17 @@ def get_current_time_in_timezone(timezone: str) -> str:
49
  except Exception as e:
50
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
51
 
52
-
53
  final_answer = FinalAnswerTool()
54
 
55
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
56
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
57
-
58
  model = HfApiModel(
59
- max_tokens=2096,
60
- temperature=0.5,
61
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
62
- custom_role_conversions=None,
63
  )
64
 
65
-
66
  # Import tool from Hub
67
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
68
 
@@ -71,7 +112,7 @@ with open("prompts.yaml", 'r') as stream:
71
 
72
  agent = CodeAgent(
73
  model=model,
74
- tools=[final_answer], ## add your tools here (don't remove final answer)
75
  max_steps=6,
76
  verbosity_level=1,
77
  grammar=None,
@@ -81,5 +122,4 @@ agent = CodeAgent(
81
  prompt_templates=prompt_templates
82
  )
83
 
84
-
85
  GradioUI(agent).launch()
 
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  from typing import List
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
32
  return "Piotrek Jan Pawel Ania".split()[:maxnb]
33
  return []
34
 
35
+ @tool
36
+ def get_next_trains_krakow_to_warszawa(count: int = 5) -> List[dict]:
37
+ """A tool that returns the next train departures from Krakow to Warszawa
38
+ Args:
39
+ count: number of train departures to return (default is 5)
40
+ """
41
+ try:
42
+ # Mock data for train schedules (in a real scenario, you would use PKP API or scraping)
43
+ # This is example data showing typical train routes
44
+ base_trains = [
45
+ {"train": "TLK 15100", "departure": "06:10", "arrival": "08:55"},
46
+ {"train": "EIP 1500", "departure": "07:00", "arrival": "09:28"},
47
+ {"train": "EIC 1502", "departure": "08:00", "arrival": "10:25"},
48
+ {"train": "TLK 15102", "departure": "09:10", "arrival": "11:55"},
49
+ {"train": "EIP 1504", "departure": "10:00", "arrival": "12:28"},
50
+ {"train": "TLK 15104", "departure": "11:10", "arrival": "13:55"},
51
+ {"train": "EIC 1506", "departure": "12:00", "arrival": "14:25"},
52
+ {"train": "TLK 15106", "departure": "13:10", "arrival": "15:55"},
53
+ {"train": "EIP 1508", "departure": "14:00", "arrival": "16:28"},
54
+ {"train": "TLK 15108", "departure": "15:10", "arrival": "17:55"},
55
+ ]
56
+
57
+ # Get current time
58
+ current_time = datetime.datetime.now(pytz.timezone('Europe/Warsaw'))
59
+ current_hour = current_time.hour
60
+ current_minute = current_time.minute
61
+
62
+ # Filter trains that haven't departed yet
63
+ upcoming_trains = []
64
+ for train in base_trains:
65
+ dep_time = train["departure"].split(":")
66
+ dep_hour = int(dep_time[0])
67
+ dep_minute = int(dep_time[1])
68
+
69
+ # Check if train hasn't departed yet
70
+ if dep_hour > current_hour or (dep_hour == current_hour and dep_minute > current_minute):
71
+ upcoming_trains.append(train)
72
+
73
+ # If no more trains today, return trains for tomorrow
74
+ if len(upcoming_trains) < count:
75
+ upcoming_trains.extend(base_trains[:count - len(upcoming_trains)])
76
+
77
+ return upcoming_trains[:count]
78
+ except Exception as e:
79
+ return [{"error": f"Failed to fetch train data: {str(e)}"}]
80
 
81
  @tool
82
+ def get_local_time(timezone: str) -> str:
83
+ """Get the current local time for a given timezone
84
  Args:
85
+ timezone: The timezone (e.g., 'America/New_York', 'Europe/London')
86
  """
87
  try:
88
  # Create timezone object
 
93
  except Exception as e:
94
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
95
 
 
96
  final_answer = FinalAnswerTool()
97
 
98
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
99
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
100
  model = HfApiModel(
101
+ max_tokens=2096,
102
+ temperature=0.5,
103
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
104
+ custom_role_conversions=None,
105
  )
106
 
 
107
  # Import tool from Hub
108
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
109
 
 
112
 
113
  agent = CodeAgent(
114
  model=model,
115
+ tools=[final_answer, get_next_trains_krakow_to_warszawa], ## add your tools here (don't remove final answer)
116
  max_steps=6,
117
  verbosity_level=1,
118
  grammar=None,
 
122
  prompt_templates=prompt_templates
123
  )
124
 
 
125
  GradioUI(agent).launch()