Pabed commited on
Commit
4dc85c6
·
verified ·
1 Parent(s): 8535740

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
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
- """A tool that fetches the public IP address of the machine running the script.
39
-
40
- Returns:
41
- A string with the public IP address.
42
- """
43
  try:
44
- # Using the ipify API to get the public IP address
45
- response = requests.get("https://api.ipify.org?format=json")
46
  ip = response.json()["ip"]
47
- return f"The public IP address is: {ip}"
 
 
 
 
48
  except Exception as e:
49
- return f"Error fetching public IP address: {str(e)}"
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()