ArslanFOX commited on
Commit
3b57ab8
·
verified ·
1 Parent(s): 90d57b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -2
app.py CHANGED
@@ -13,7 +13,13 @@ import requests
13
  @tool
14
  def get_timezone_by_city(city: str) -> str:
15
  """
16
- Get the timezone string for a given city name.
 
 
 
 
 
 
17
  """
18
  if not isinstance(city, str):
19
  return f"Error: Expected a string for city, got: {type(city)}"
@@ -35,6 +41,12 @@ def get_timezone_by_city(city: str) -> str:
35
  def get_current_time_in_timezone(timezone: str) -> str:
36
  """
37
  Return the current local time in the specified timezone.
 
 
 
 
 
 
38
  """
39
  try:
40
  tz = pytz.timezone(timezone)
@@ -47,6 +59,13 @@ def get_current_time_in_timezone(timezone: str) -> str:
47
  def get_air_quality(city: str, lang: str = "en") -> str:
48
  """
49
  Return formatted air quality information for a given city.
 
 
 
 
 
 
 
50
  """
51
  try:
52
  geolocator = Nominatim(user_agent="smolagents_bot")
@@ -79,6 +98,13 @@ def get_air_quality(city: str, lang: str = "en") -> str:
79
  def get_weather(city: str, lang: str = "en") -> str:
80
  """
81
  Return formatted weather information for a given city.
 
 
 
 
 
 
 
82
  """
83
  try:
84
  geolocator = Nominatim(user_agent="smolagents_bot")
@@ -104,6 +130,12 @@ def get_weather(city: str, lang: str = "en") -> str:
104
  def final_answer(answer: str) -> str:
105
  """
106
  Return the final answer string to be displayed to the user.
 
 
 
 
 
 
107
  """
108
  return answer
109
 
@@ -124,7 +156,13 @@ system_prompt = (
124
 
125
  agent = CodeAgent(
126
  model=model,
127
- tools=[get_timezone_by_city, get_current_time_in_timezone, get_air_quality, get_weather, final_answer],
 
 
 
 
 
 
128
  prompt_templates={
129
  "system_prompt": system_prompt,
130
  "default": "Response: {{question}}"
 
13
  @tool
14
  def get_timezone_by_city(city: str) -> str:
15
  """
16
+ Get the timezone string for a given city.
17
+
18
+ Args:
19
+ city (str): Name of the city (e.g., 'Berlin', 'Бирск').
20
+
21
+ Returns:
22
+ str: Timezone name (e.g., 'Europe/Moscow') or an error message.
23
  """
24
  if not isinstance(city, str):
25
  return f"Error: Expected a string for city, got: {type(city)}"
 
41
  def get_current_time_in_timezone(timezone: str) -> str:
42
  """
43
  Return the current local time in the specified timezone.
44
+
45
+ Args:
46
+ timezone (str): A valid timezone name (e.g., 'Europe/Moscow').
47
+
48
+ Returns:
49
+ str: Current local time as a string or an error message.
50
  """
51
  try:
52
  tz = pytz.timezone(timezone)
 
59
  def get_air_quality(city: str, lang: str = "en") -> str:
60
  """
61
  Return formatted air quality information for a given city.
62
+
63
+ Args:
64
+ city (str): City name (e.g., 'Berlin').
65
+ lang (str): Language code (e.g., 'en', 'ru') — currently unused.
66
+
67
+ Returns:
68
+ str: Human-readable air quality info or error message.
69
  """
70
  try:
71
  geolocator = Nominatim(user_agent="smolagents_bot")
 
98
  def get_weather(city: str, lang: str = "en") -> str:
99
  """
100
  Return formatted weather information for a given city.
101
+
102
+ Args:
103
+ city (str): City name (e.g., 'Berlin').
104
+ lang (str): Language code (e.g., 'en', 'ru') — currently unused.
105
+
106
+ Returns:
107
+ str: Weather description with temperature and humidity or error message.
108
  """
109
  try:
110
  geolocator = Nominatim(user_agent="smolagents_bot")
 
130
  def final_answer(answer: str) -> str:
131
  """
132
  Return the final answer string to be displayed to the user.
133
+
134
+ Args:
135
+ answer (str): Final response to present.
136
+
137
+ Returns:
138
+ str: The same response passed in.
139
  """
140
  return answer
141
 
 
156
 
157
  agent = CodeAgent(
158
  model=model,
159
+ tools=[
160
+ get_timezone_by_city,
161
+ get_current_time_in_timezone,
162
+ get_air_quality,
163
+ get_weather,
164
+ final_answer,
165
+ ],
166
  prompt_templates={
167
  "system_prompt": system_prompt,
168
  "default": "Response: {{question}}"