-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
import requests | ||
from retry import retry | ||
|
||
from danswer.utils.logger import setup_logger | ||
from shared_configs.configs import INDEXING_MODEL_SERVER_HOST | ||
from shared_configs.configs import INDEXING_MODEL_SERVER_PORT | ||
from shared_configs.configs import MODEL_SERVER_HOST | ||
from shared_configs.configs import MODEL_SERVER_PORT | ||
|
||
logger = setup_logger() | ||
|
||
|
||
def gpu_status_request(indexing: bool = False) -> bool: | ||
model_server_url = f"{MODEL_SERVER_HOST}:{MODEL_SERVER_PORT}" | ||
@retry(tries=5, delay=5) | ||
def gpu_status_request(indexing: bool = True) -> bool: | ||
if indexing: | ||
model_server_url = f"{INDEXING_MODEL_SERVER_HOST}:{INDEXING_MODEL_SERVER_PORT}" | ||
else: | ||
model_server_url = f"{MODEL_SERVER_HOST}:{MODEL_SERVER_PORT}" | ||
|
||
if "http" not in model_server_url: | ||
model_server_url = f"http://{model_server_url}" | ||
|
||
response = requests.get(f"{model_server_url}/api/gpu-status") | ||
|
||
if response.status_code == 200: | ||
try: | ||
response = requests.get(f"{model_server_url}/api/gpu-status", timeout=10) | ||
response.raise_for_status() | ||
gpu_status = response.json() | ||
if gpu_status["gpu_available"]: | ||
return True | ||
else: | ||
return False | ||
else: | ||
logger.warning( | ||
f"Error: Unable to fetch GPU status. Status code: {response.status_code}" | ||
) | ||
return False | ||
return gpu_status["gpu_available"] | ||
except requests.RequestException as e: | ||
logger.error(f"Error: Unable to fetch GPU status. Error: {str(e)}") | ||
raise # Re-raise exception to trigger a retry |