Skip to content

Commit

Permalink
Test connectivity with requests instead of ping
Browse files Browse the repository at this point in the history
  • Loading branch information
luandro committed Mar 25, 2024
1 parent d5054bc commit 3ffc013
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions app/internal/rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from shutil import rmtree

import requests
from dotenv import load_dotenv

# LlamaIndex
Expand Down Expand Up @@ -38,13 +39,14 @@
if local_mode:
print("Running in local mode")
else:
response = os.system("ping -c 1 8.8.8.8")
if response == 0:
print("Running in cloud mode")
else:
print("Cloud mode connectivity failed, switching to local mode")
connectivity_test_url = "https://httpbin.org/get"
try:
with requests.get(connectivity_test_url, timeout=5) as response:
response.raise_for_status() # Will raise an HTTPError if the HTTP request returned an unsuccessful status code
print("Running in cloud mode")
except (requests.ConnectionError, requests.Timeout, requests.HTTPError) as e:
print(f"Cloud mode connectivity failed ({e}), switching to local mode")
local_mode = True

# Setup LLM
used_llm = setup_llm(local_mode)
# Setup Langfuse as handler
Expand Down

0 comments on commit 3ffc013

Please sign in to comment.