From 28537b6a84ce51487f477e2619d1c177e08f399b Mon Sep 17 00:00:00 2001 From: VaiTon Date: Thu, 6 Jul 2023 00:16:11 +0200 Subject: [PATCH] Better error message if .env is empty/does not exist. --- constants.py | 2 ++ ingest.py | 7 ++++--- privateGPT.py | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/constants.py b/constants.py index ca3b8a163..366a48a6d 100644 --- a/constants.py +++ b/constants.py @@ -6,6 +6,8 @@ # Define the folder for storing database PERSIST_DIRECTORY = os.environ.get('PERSIST_DIRECTORY') +if PERSIST_DIRECTORY is None: + raise Exception("Please set the PERSIST_DIRECTORY environment variable") # Define the Chroma settings CHROMA_SETTINGS = Settings( diff --git a/ingest.py b/ingest.py index 0ca80743f..825d73269 100755 --- a/ingest.py +++ b/ingest.py @@ -24,11 +24,12 @@ from langchain.vectorstores import Chroma from langchain.embeddings import HuggingFaceEmbeddings from langchain.docstore.document import Document -from constants import CHROMA_SETTINGS - -load_dotenv() +if not load_dotenv(): + print("Could not load .env file or it is empty. Please check if it exists and is readable.") + exit(1) +from constants import CHROMA_SETTINGS # Load environment variables persist_directory = os.environ.get('PERSIST_DIRECTORY') diff --git a/privateGPT.py b/privateGPT.py index 0e3b9d04d..74b3ca6f7 100755 --- a/privateGPT.py +++ b/privateGPT.py @@ -9,7 +9,9 @@ import argparse import time -load_dotenv() +if not load_dotenv(): + print("Could not load .env file or it is empty. Please check if it exists and is readable.") + exit(1) embeddings_model_name = os.environ.get("EMBEDDINGS_MODEL_NAME") persist_directory = os.environ.get('PERSIST_DIRECTORY') @@ -39,7 +41,7 @@ def main(): case _default: # raise exception if model_type is not supported raise Exception(f"Model type {model_type} is not supported. Please choose one of the following: LlamaCpp, GPT4All") - + qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever, return_source_documents= not args.hide_source) # Interactive questions and answers while True: