Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -35,18 +35,18 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def get_public_ip_address() -> str:
|
| 38 |
-
"""
|
| 39 |
-
|
| 40 |
-
Returns:
|
| 41 |
-
A string with the public IP address.
|
| 42 |
-
"""
|
| 43 |
try:
|
| 44 |
-
|
| 45 |
-
response
|
| 46 |
ip = response.json()["ip"]
|
| 47 |
-
return f"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
except Exception as e:
|
| 49 |
-
return f"
|
| 50 |
|
| 51 |
|
| 52 |
final_answer = FinalAnswerTool()
|
|
|
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def get_public_ip_address() -> str:
|
| 38 |
+
"""Fetches the machine's public IP address."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
try:
|
| 40 |
+
response = requests.get("https://api.ipify.org?format=json", timeout=5)
|
| 41 |
+
response.raise_for_status() # Raise HTTP errors
|
| 42 |
ip = response.json()["ip"]
|
| 43 |
+
return f"Public IP: {ip}"
|
| 44 |
+
except requests.exceptions.RequestException as e:
|
| 45 |
+
return f"Network error: {e}"
|
| 46 |
+
except KeyError:
|
| 47 |
+
return "Error: Invalid API response"
|
| 48 |
except Exception as e:
|
| 49 |
+
return f"Unexpected error: {e}"
|
| 50 |
|
| 51 |
|
| 52 |
final_answer = FinalAnswerTool()
|