feat : improve chrome path check + no query refusal on complex task
This commit is contained in:
+16
-13
@@ -7,7 +7,9 @@ import requests
|
||||
import subprocess
|
||||
import ipaddress
|
||||
import httpx
|
||||
import socket
|
||||
import platform
|
||||
from urllib.parse import urlparse
|
||||
from dotenv import load_dotenv, set_key
|
||||
from openai import OpenAI
|
||||
from huggingface_hub import InferenceClient
|
||||
@@ -95,25 +97,26 @@ class Provider:
|
||||
raise Exception(f"Provider {self.provider_name} failed: {str(e)}") from e
|
||||
return thought
|
||||
|
||||
def is_ip_online(self, ip_address):
|
||||
def is_ip_online(self, address: str, timeout: int = 10) -> bool:
|
||||
"""
|
||||
Check if an IP address is online by sending a ping request.
|
||||
Check if an address is online by sending a ping request.
|
||||
"""
|
||||
if ip_address == "127.0.0.1":
|
||||
if not address:
|
||||
return False
|
||||
if address.lower() in ["127.0.0.1", "localhost", "0.0.0.0"]:
|
||||
return True
|
||||
hostname = urlparse(f'http://{address}' if not address.startswith(('http://', 'https://')) else address).hostname or address
|
||||
try:
|
||||
ip_address = socket.gethostbyname(hostname)
|
||||
except socket.gaierror:
|
||||
self.logger.error(f"Cannot resolve: {hostname}")
|
||||
return False
|
||||
param = '-n' if platform.system().lower() == 'windows' else '-c'
|
||||
command = ['ping', param, '1', ip_address]
|
||||
try:
|
||||
output = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=15)
|
||||
if output.returncode == 0:
|
||||
return True
|
||||
else:
|
||||
self.logger.error(f"Ping command returned code: {output.returncode}")
|
||||
return False
|
||||
except subprocess.TimeoutExpired:
|
||||
return False
|
||||
except Exception as e:
|
||||
pretty_print(f"Error with ping request {str(e)}", color="failure")
|
||||
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout)
|
||||
return result.returncode == 0
|
||||
except (subprocess.TimeoutExpired, subprocess.SubprocessError) as e:
|
||||
return False
|
||||
|
||||
def server_fn(self, history, verbose = False):
|
||||
|
||||
Reference in New Issue
Block a user