Eurico149 commited on
Commit
6fa006d
·
1 Parent(s): c621c5e

feat: get_weather tool

Browse files
Files changed (5) hide show
  1. .gitignore +2 -1
  2. app.py +5 -4
  3. requirements.txt +3 -0
  4. tools/__init__.py +1 -0
  5. tools/weather.py +32 -0
.gitignore CHANGED
@@ -1,2 +1,3 @@
1
  /.idea
2
- .venv/
 
 
1
  /.idea
2
+ .venv/
3
+ */__pycache__/
app.py CHANGED
@@ -1,8 +1,9 @@
1
- from dataclasses import asdict
2
- from smolagents import CodeAgent, TransformersModel, InferenceClientModel, stream_to_gradio
3
  import torch
4
  import gradio as gr
 
 
5
  from transformers import BitsAndBytesConfig
 
6
 
7
 
8
  model_path = "Qwen/Qwen3-4B-Instruct-2507"
@@ -24,9 +25,9 @@ else:
24
  )
25
 
26
  agent = CodeAgent(
27
- tools=[],
28
  model=model,
29
- max_steps=6,
30
  verbosity_level=2,
31
  add_base_tools=True
32
  )
 
 
 
1
  import torch
2
  import gradio as gr
3
+ from dataclasses import asdict
4
+ from smolagents import CodeAgent, TransformersModel, InferenceClientModel, stream_to_gradio
5
  from transformers import BitsAndBytesConfig
6
+ from tools import get_weather
7
 
8
 
9
  model_path = "Qwen/Qwen3-4B-Instruct-2507"
 
25
  )
26
 
27
  agent = CodeAgent(
28
+ tools=[get_weather],
29
  model=model,
30
+ max_steps=8,
31
  verbosity_level=2,
32
  add_base_tools=True
33
  )
requirements.txt CHANGED
@@ -13,6 +13,7 @@ fastapi==0.118.0
13
  ffmpy==0.6.1
14
  filelock==3.19.1
15
  fsspec==2025.9.0
 
16
  gradio==5.49.0
17
  gradio_client==1.13.3
18
  groovy==0.1.2
@@ -57,6 +58,8 @@ pydantic==2.11.10
57
  pydantic_core==2.33.2
58
  pydub==0.25.1
59
  Pygments==2.19.2
 
 
60
  python-dateutil==2.9.0.post0
61
  python-dotenv==1.1.1
62
  python-multipart==0.0.20
 
13
  ffmpy==0.6.1
14
  filelock==3.19.1
15
  fsspec==2025.9.0
16
+ geojson==3.2.0
17
  gradio==5.49.0
18
  gradio_client==1.13.3
19
  groovy==0.1.2
 
58
  pydantic_core==2.33.2
59
  pydub==0.25.1
60
  Pygments==2.19.2
61
+ pyowm==3.5.0
62
+ PySocks==1.7.1
63
  python-dateutil==2.9.0.post0
64
  python-dotenv==1.1.1
65
  python-multipart==0.0.20
tools/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from .weather import get_weather
tools/weather.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pyowm import OWM
2
+ from smolagents import tool
3
+ import os
4
+
5
+
6
+ @tool
7
+ def get_weather(city: str, nation: str) -> str:
8
+ """
9
+ This tool returns the current weather for one specific city.
10
+
11
+ Args:
12
+ city: The city to search the weather.
13
+ nation: The nation where the city is located.
14
+ """
15
+ API_KEY = os.getenv("OPENWEATHER_API_KEY")
16
+ owm = OWM(API_KEY)
17
+ mgr = owm.weather_manager()
18
+
19
+ location = f'{city}, {nation}'
20
+
21
+ observation = mgr.weather_at_place(location)
22
+ w = observation.weather
23
+
24
+ temperature = w.temperature('celsius')['temp']
25
+ status = w.detailed_status
26
+ humidity = w.humidity
27
+
28
+ return f"Location: {location}\nStatus: {status}\nTemperature: {temperature}\nHumidity: {humidity}%"
29
+
30
+
31
+ if __name__ == "__main__":
32
+ print(get_weather('Sao Paulo', 'BR'))