Skip to content

Commit

Permalink
Better method to validate localai server is running
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinfrlch committed May 22, 2024
1 parent b7d95c1 commit 83fcccb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 8 additions & 7 deletions custom_components/gpt4vision/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .const import DOMAIN, CONF_OPENAI_API_KEY, CONF_IP_ADDRESS, CONF_PORT
import voluptuous as vol
import logging
import socket
import requests

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -35,13 +35,14 @@ def validate_openai(user_input: dict):


def validate_connection(ip_address, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1) # One second timeout
url = f'http://{ip_address}:{port}/readyz'
try:
sock.connect((ip_address, port))
sock.close()
return True
except socket.error:
response = requests.get(url)
if response.status_code == 200:
return True
else:
return False
except requests.exceptions.RequestException as e:
return False


Expand Down
5 changes: 5 additions & 0 deletions localai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import requests

url = 'http://localhost:8080/readyz'
response = requests.get(url)
print(response)

0 comments on commit 83fcccb

Please sign in to comment.