Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAdding weather tool to the agent
app.py
CHANGED
|
@@ -9,7 +9,7 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
"""A tool that does nothing yet
|
| 15 |
Args:
|
|
@@ -32,7 +32,22 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 32 |
return f"The current local time in {timezone} is: {local_time}"
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
model = HfApiModel(
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 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 does nothing yet
|
| 15 |
Args:
|
|
|
|
| 32 |
return f"The current local time in {timezone} is: {local_time}"
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
+
@tool
|
| 36 |
+
def get_weather(city):
|
| 37 |
+
import requests
|
| 38 |
+
api_url = f"https://api.weather.com/v1/location/{city}?apiKey=YOUR_API_KEY"
|
| 39 |
+
response = requests.get(api_url)
|
| 40 |
+
if response.status_code == 200:
|
| 41 |
+
data = response.json()
|
| 42 |
+
return data.get("weather", "No weather information available")
|
| 43 |
+
else:
|
| 44 |
+
return "Error: Unable to fetch weather data."
|
| 45 |
+
|
| 46 |
+
# Execute the function and prepare the final answer
|
| 47 |
|
| 48 |
+
result = get_weather("New York")
|
| 49 |
+
final_answer = f"The current weather in New York is: {result}"
|
| 50 |
+
print(final_answer)
|
| 51 |
|
| 52 |
final_answer = FinalAnswerTool()
|
| 53 |
model = HfApiModel(
|