Update app.py
#247
by
diamantk
- opened
app.py
CHANGED
|
@@ -11,12 +11,23 @@ from Gradio_UI import GradioUI
|
|
| 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
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 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 fetches the current weather for a given city.
|
| 15 |
Args:
|
| 16 |
+
city: The name of the city.
|
| 17 |
+
api_key: Your OpenWeatherMap API key.
|
| 18 |
"""
|
| 19 |
+
try:
|
| 20 |
+
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
|
| 21 |
+
response = requests.get(url)
|
| 22 |
+
data = response.json()
|
| 23 |
+
if response.status_code == 200:
|
| 24 |
+
weather = data['weather'][0]['description']
|
| 25 |
+
temp = data['main']['temp']
|
| 26 |
+
return f"The weather in {city} is {weather} with a temperature of {temp}°C."
|
| 27 |
+
else:
|
| 28 |
+
return f"Error fetching weather: {data.get('message', 'Unknown error')}"
|
| 29 |
+
except Exception as e:
|
| 30 |
+
return f"Error fetching weather data: {str(e)}"
|
| 31 |
|
| 32 |
@tool
|
| 33 |
def get_current_time_in_timezone(timezone: str) -> str:
|