From 5bc4d666ea64fd26c984858a90c0d30bdf5728ca Mon Sep 17 00:00:00 2001 From: Char15Xu Date: Mon, 12 Aug 2024 17:08:49 -0700 Subject: [PATCH 1/3] updating readme --- ai_course_bot/ai-chatbot-backend/README.md | 8 +++++--- .../ai-chatbot-backend/app/core/actions/llama_seletor.py | 4 ++-- rag/file_conversion_router/embedding/README | 5 +++++ 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 rag/file_conversion_router/embedding/README diff --git a/ai_course_bot/ai-chatbot-backend/README.md b/ai_course_bot/ai-chatbot-backend/README.md index afccd83..064c331 100755 --- a/ai_course_bot/ai-chatbot-backend/README.md +++ b/ai_course_bot/ai-chatbot-backend/README.md @@ -4,8 +4,10 @@ 3. run server `python main.py` ### Configure SQLite Support -1. To enable SQLite support, please set `SQLDB = True` in `ai_course_bot/ai-chatbot-backend/app/core/actions/llama_seletor.py` +1. Download the appropriate `vector0.dylib` and `vss0.dylib` for your machine's hardware from https://github.com/asg017/sqlite-vss/releases. Place `vector0.dylib` and `vss0.dylib` files into the `ai_course_bot/ai-chatbot-backend/app/core/actions/dist/debug` directory. -2. Download the appropriate `vector0.dylib` and `vss0.dylib` for your machine's hardware from https://github.com/asg017/sqlite-vss/releases. +2. To enable SQLite support, please set `SQLDB = True` in `ai_course_bot/ai-chatbot-backend/app/core/actions/llama_seletor.py` -3. Place `vector0.dylib` and `vss0.dylib` files into the `rag/file_conversion_router/embedding/dist/debug` directory. \ No newline at end of file +3. Make sure `current_dir` under `func llama_selector` is set to the correct file path + +4. Running python ai_course_bot/ai-chatbot-backend/main.py and launch http://0.0.0.0:8000 in prefered browser \ No newline at end of file diff --git a/ai_course_bot/ai-chatbot-backend/app/core/actions/llama_seletor.py b/ai_course_bot/ai-chatbot-backend/app/core/actions/llama_seletor.py index 0d29dcb..e835cbf 100755 --- a/ai_course_bot/ai-chatbot-backend/app/core/actions/llama_seletor.py +++ b/ai_course_bot/ai-chatbot-backend/app/core/actions/llama_seletor.py @@ -36,7 +36,7 @@ class Message(BaseModel): "text-generation", model=model_id, model_kwargs={"torch_dtype": torch.bfloat16}, - device="cuda", + device="cuda", ) lock = threading.Lock() @@ -124,7 +124,7 @@ def local_selector(messages:List[Message],stream=True,rag=True,course=None): picklefile = "cs61a.pkl" else: picklefile = "Berkeley.pkl" - current_dir = "/home/roar-tai-1/charles/roarai/rag/file_conversion_router/embedding" + current_dir = "roarai/rag/file_conversion_router/embedding" # Modify this path to the directory containing the embedding pickle files query_embed = embedding_model.encode(user_message, return_dense=True, return_sparse=True, return_colbert_vecs=True) if SQLDB: diff --git a/rag/file_conversion_router/embedding/README b/rag/file_conversion_router/embedding/README new file mode 100644 index 0000000..bbcda37 --- /dev/null +++ b/rag/file_conversion_router/embedding/README @@ -0,0 +1,5 @@ +### Configure SQLite Support + +1. Download the appropriate `vector0.dylib` and `vss0.dylib` for your machine's hardware from https://github.com/asg017/sqlite-vss/releases. Place `vector0.dylib` and `vss0.dylib` files into the `rag/file_conversion_router/embedding/dist/debug` directory. + +2. Running `python rag/file_conversion_router/embedding/table_create.py` will create `embeddings.db` and `[picklefile_name].db` under the current running directory. \ No newline at end of file From 96274c9a676aaa2c2043521ac0e67d1374c7f387 Mon Sep 17 00:00:00 2001 From: Char15Xu Date: Mon, 12 Aug 2024 17:10:46 -0700 Subject: [PATCH 2/3] syntax revision --- .../ai-chatbot-backend/app/core/actions/llama_seletor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai_course_bot/ai-chatbot-backend/app/core/actions/llama_seletor.py b/ai_course_bot/ai-chatbot-backend/app/core/actions/llama_seletor.py index e835cbf..983a423 100755 --- a/ai_course_bot/ai-chatbot-backend/app/core/actions/llama_seletor.py +++ b/ai_course_bot/ai-chatbot-backend/app/core/actions/llama_seletor.py @@ -36,7 +36,7 @@ class Message(BaseModel): "text-generation", model=model_id, model_kwargs={"torch_dtype": torch.bfloat16}, - device="cuda", + device="cuda", ) lock = threading.Lock() From c11a145ae9baf9e6a68d3ac7a7e55dac33eef8aa Mon Sep 17 00:00:00 2001 From: Char15Xu Date: Mon, 12 Aug 2024 17:32:11 -0700 Subject: [PATCH 3/3] organizing file path in table_create --- rag/file_conversion_router/embedding/README | 4 +++- .../embedding/table_create.py | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/rag/file_conversion_router/embedding/README b/rag/file_conversion_router/embedding/README index bbcda37..748ba19 100644 --- a/rag/file_conversion_router/embedding/README +++ b/rag/file_conversion_router/embedding/README @@ -2,4 +2,6 @@ 1. Download the appropriate `vector0.dylib` and `vss0.dylib` for your machine's hardware from https://github.com/asg017/sqlite-vss/releases. Place `vector0.dylib` and `vss0.dylib` files into the `rag/file_conversion_router/embedding/dist/debug` directory. -2. Running `python rag/file_conversion_router/embedding/table_create.py` will create `embeddings.db` and `[picklefile_name].db` under the current running directory. \ No newline at end of file +2. Ensure that `DIRECTORY_PATH` points to the correct directory containing the necessary pickle file. + +3. Running `python rag/file_conversion_router/embedding/table_create.py` will create `embeddings.db` and `[picklefile_name].db` under the current running directory. \ No newline at end of file diff --git a/rag/file_conversion_router/embedding/table_create.py b/rag/file_conversion_router/embedding/table_create.py index a100d03..f05b42b 100644 --- a/rag/file_conversion_router/embedding/table_create.py +++ b/rag/file_conversion_router/embedding/table_create.py @@ -9,6 +9,8 @@ EXT_VSS_PATH = "rag/file_conversion_router/embedding/dist/debug/vss0" BGE = True +# Modify this path to the directory containing the embedding pickle files and the database +DIRECTORY_PATH = 'roarai/rag/file_conversion_router/embedding' # Connect to the SQLite database and load extensions def connect(path=":memory:"): @@ -77,9 +79,8 @@ def get_structure_debug(pickle_data): def create_embedding_table(pickle_data): - directory_path = '/home/roar-tai-1/charles/roarai/rag/file_conversion_router/embedding' - os.makedirs(directory_path, exist_ok=True) - db_path = os.path.join(directory_path, 'embeddings.db') + os.makedirs(DIRECTORY_PATH, exist_ok=True) + db_path = os.path.join(DIRECTORY_PATH, 'embeddings.db') db = connect(db_path) print(db_path) cur = db.cursor() @@ -136,9 +137,8 @@ def create_main_table(filename, pickle_data): else: raise ValueError("The provided file does not have a .pkl extension") - directory_path = '/home/roar-tai-1/charles/roarai/rag/file_conversion_router/embedding' - os.makedirs(directory_path, exist_ok=True) - db_path = os.path.join(directory_path, database_name) + os.makedirs(DIRECTORY_PATH, exist_ok=True) + db_path = os.path.join(DIRECTORY_PATH, database_name) print(db_path) db = sqlite3.connect(db_path) cur = db.cursor() @@ -183,7 +183,7 @@ def create_main_table(filename, pickle_data): def main(): ee106b = "rag/file_conversion_router/embedding/eecs106b.pkl" path_to_pickle = ee106b - # path_to_pickle = "rag/file_conversion_router/embedding/cs61a_7_24.pkl" + # path_to_pickle = "rag/file_conversion_router/embedding/cs61a.pkl" with open(path_to_pickle, 'rb') as f: data_loaded = pickle.load(f)