From f9e09ba49006cdfabbdec9b24459931da78ffc67 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Sat, 19 Aug 2023 19:08:09 -0700 Subject: [PATCH] Do not try downloading model from GPT4All if the user is not connected to the internet --- src/khoj/processor/conversation/gpt4all/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/khoj/processor/conversation/gpt4all/utils.py b/src/khoj/processor/conversation/gpt4all/utils.py index 25539c02..21f3afb4 100644 --- a/src/khoj/processor/conversation/gpt4all/utils.py +++ b/src/khoj/processor/conversation/gpt4all/utils.py @@ -29,6 +29,12 @@ def download_model(model_name: str): filename = os.path.expanduser(f"~/.cache/gpt4all/{model_name}") if os.path.exists(filename): + # Check if the user is connected to the internet + try: + requests.get("https://www.google.com/", timeout=5) + except: + logger.debug("User is offline. Disabling allowed download flag") + return GPT4All(model_name, allow_download=False) return GPT4All(model_name) # Download the model to a tmp file. Once the download is completed, move the tmp file to the actual file