优化cli_demo.py的逻辑:支持 输入提示;多输入;重新输入
This commit is contained in:
parent
660f8c6715
commit
b262612248
|
|
@ -196,7 +196,9 @@ class LocalDocQA:
|
|||
return vs_path, loaded_files
|
||||
else:
|
||||
logger.info("文件均未成功加载,请检查依赖包或替换为其他文件再次上传。")
|
||||
return None, loaded_files
|
||||
# 若len(docs) !> 0,必然是所有文件均未加载成功,loaded_files必然为[],返回没有实际意义
|
||||
# 而若只返回None,可以跟上文的异常返回值保持一致,更便于下游任务判断
|
||||
return None
|
||||
|
||||
def one_knowledge_add(self, vs_path, one_title, one_conent, one_content_segmentation, sentence_size):
|
||||
try:
|
||||
|
|
|
|||
22
cli_demo.py
22
cli_demo.py
|
|
@ -23,11 +23,31 @@ def main():
|
|||
top_k=VECTOR_SEARCH_TOP_K)
|
||||
vs_path = None
|
||||
while not vs_path:
|
||||
print("注意输入的路径是完整的文件路径,例如content/`knowledge_base_id`/file.md,多个路径用英文逗号分割")
|
||||
filepath = input("Input your local knowledge file path 请输入本地知识文件路径:")
|
||||
|
||||
# 判断 filepath 是否为空,如果为空的话,重新让用户输入,防止用户误触回车
|
||||
if not filepath:
|
||||
continue
|
||||
vs_path, _ = local_doc_qa.init_knowledge_vector_store(filepath)
|
||||
|
||||
# 支持加载多个文件
|
||||
filepath = filepath.split(",")
|
||||
# filepath错误的返回为None, 如果直接用原先的vs_path,_ = local_doc_qa.init_knowledge_vector_store(filepath)
|
||||
# 会直接导致TypeError: cannot unpack non-iterable NoneType object而使得程序直接退出
|
||||
# 因此需要先加一层判断,保证程序能继续运行
|
||||
temp = local_doc_qa.init_knowledge_vector_store(filepath)
|
||||
if temp is not None:
|
||||
vs_path,loaded_files = temp
|
||||
if len(loaded_files) != len(filepath):
|
||||
reload_flag = eval(input("部分文件加载失败,若提示路径不存在,可重新加载,是否重新加载,输入True或False: "))
|
||||
if reload_flag:
|
||||
vs_path = None
|
||||
continue
|
||||
|
||||
print(f"the loaded vs_path is 加载的vs_path为: {vs_path}")
|
||||
else:
|
||||
print("load file failed, re-input your local knowledge file path 请重新输入本地知识文件路径")
|
||||
|
||||
history = []
|
||||
while True:
|
||||
query = input("Input your question 请输入问题:")
|
||||
|
|
|
|||
Loading…
Reference in New Issue