From 90024caf384fc704c647231e3bcc01c933bcff2d Mon Sep 17 00:00:00 2001 From: malekinho8 Date: Thu, 13 Apr 2023 01:51:16 -0400 Subject: [PATCH] Added an option for the user to specify a repo folder by providing a specific path if desired. --- app.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 4db0448..17388d1 100644 --- a/app.py +++ b/app.py @@ -13,6 +13,7 @@ STORE_DIR = "store" CLONE_NEW_REPO = "Clone new repo" LOAD_EXISTING_INDEX = "Load existing index" +SPECIFIC_FOLDER = "Specify a specific folder path" def ask_for_repo(): repo_url = input("Enter repo url: ") @@ -100,6 +101,22 @@ def existing_repo_flow(): return index +def folder_path_flow(): + # Ask user to enter the folder path + folder_path = input("Enter the folder path of the repo: ") + + # Check if the folder exists + if not os.path.exists(folder_path): + print("The specified folder does not exist. Exiting...") + return None + + # Load documents & create the index + print("Creating index...") + documents = SimpleDirectoryReader(input_dir=folder_path, exclude_hidden=True).load_data() + index = GPTSimpleVectorIndex(documents) + + return index + def main(): # Declare index index = None @@ -122,7 +139,7 @@ def main(): # Ask if user wants to clone new repo or load existing index answer = inquirer.prompt( [inquirer.List("type", message="Would you like to clone a new repo or load an existing index?", choices=[ - CLONE_NEW_REPO, LOAD_EXISTING_INDEX + CLONE_NEW_REPO, LOAD_EXISTING_INDEX, SPECIFIC_FOLDER ])] )["type"] @@ -133,6 +150,8 @@ def main(): elif answer == LOAD_EXISTING_INDEX: # Existing index index = existing_repo_flow() + elif answer == SPECIFIC_FOLDER: + index = folder_path_flow() else: print("Invalid input, exiting...") return