From 55071c79ef3a2c880b7317be39a003aebe4d435d Mon Sep 17 00:00:00 2001 From: imClumsyPanda Date: Tue, 11 Apr 2023 23:02:24 +0800 Subject: [PATCH] Add support for folder path as input --- knowledge_based_chatglm.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/knowledge_based_chatglm.py b/knowledge_based_chatglm.py index 473515c..b073873 100644 --- a/knowledge_based_chatglm.py +++ b/knowledge_based_chatglm.py @@ -55,9 +55,14 @@ def init_knowledge_vector_store(filepath:str): print("路径不存在") return None elif os.path.isfile(filepath): - loader = UnstructuredFileLoader(filepath, mode="elements") - docs = loader.load() - print(f"{os.path.split(filepath)[-1]} 已成功加载") + file = os.path.split(filepath)[-1] + try: + loader = UnstructuredFileLoader(filepath, mode="elements") + docs = loader.load() + print(f"{file} 已成功加载") + except: + print(f"{file} 未能成功加载") + return None elif os.path.isdir(filepath): docs = [] for file in os.listdir(filepath):