Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,17 +7,22 @@ from smolagents import tool, CodeAgent, HfApiModel, GoogleSearchTool, VisitWebpa
|
|
| 7 |
OPENWEATHER_API_KEY = os.environ.get("OPENWEATHER_API_KEY")
|
| 8 |
SERPER_API_KEY = os.environ.get("SERPER_API_KEY")
|
| 9 |
|
|
|
|
| 10 |
@tool
|
| 11 |
def get_weather(lat: float, lon: float) -> dict | None:
|
| 12 |
"""
|
| 13 |
Gọi API OpenWeatherMap để lấy thông tin thời tiết theo tọa độ địa lý
|
| 14 |
|
| 15 |
Args:
|
| 16 |
-
lat : Vĩ độ của địa điểm
|
| 17 |
-
lon : Kinh độ của địa điểm
|
| 18 |
|
| 19 |
Returns:
|
| 20 |
-
dict: Dictionary chứa
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
"""
|
| 22 |
url = f"https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={OPENWEATHER_API_KEY}&units=metric"
|
| 23 |
try:
|
|
@@ -34,7 +39,7 @@ def get_weather(lat: float, lon: float) -> dict | None:
|
|
| 34 |
except Exception as e:
|
| 35 |
print(f"Lỗi API thời tiết: {e}")
|
| 36 |
return None
|
| 37 |
-
|
| 38 |
weather_agent = CodeAgent(
|
| 39 |
model=HfApiModel("deepseek-ai/DeepSeek-R1", max_tokens=8096, provider="together"),
|
| 40 |
tools=[GoogleSearchTool(provider="serper"), get_weather],
|
|
|
|
| 7 |
OPENWEATHER_API_KEY = os.environ.get("OPENWEATHER_API_KEY")
|
| 8 |
SERPER_API_KEY = os.environ.get("SERPER_API_KEY")
|
| 9 |
|
| 10 |
+
@tool
|
| 11 |
@tool
|
| 12 |
def get_weather(lat: float, lon: float) -> dict | None:
|
| 13 |
"""
|
| 14 |
Gọi API OpenWeatherMap để lấy thông tin thời tiết theo tọa độ địa lý
|
| 15 |
|
| 16 |
Args:
|
| 17 |
+
lat (float): Vĩ độ của địa điểm (từ -90 đến 90)
|
| 18 |
+
lon (float): Kinh độ của địa điểm (từ -180 đến 180)
|
| 19 |
|
| 20 |
Returns:
|
| 21 |
+
dict | None: Dictionary chứa thông tin thời tiết hoặc None nếu có lỗi. Cấu trúc:
|
| 22 |
+
- condition (str): Mô tả điều kiện thời tiết
|
| 23 |
+
- temperature (float): Nhiệt độ (°C)
|
| 24 |
+
- humidity (float): Độ ẩm (%)
|
| 25 |
+
- wind_speed (float): Tốc độ gió (m/s)
|
| 26 |
"""
|
| 27 |
url = f"https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={OPENWEATHER_API_KEY}&units=metric"
|
| 28 |
try:
|
|
|
|
| 39 |
except Exception as e:
|
| 40 |
print(f"Lỗi API thời tiết: {e}")
|
| 41 |
return None
|
| 42 |
+
|
| 43 |
weather_agent = CodeAgent(
|
| 44 |
model=HfApiModel("deepseek-ai/DeepSeek-R1", max_tokens=8096, provider="together"),
|
| 45 |
tools=[GoogleSearchTool(provider="serper"), get_weather],
|