From 74e3470b888abfbff75b58e3e96e2f10d0787d1b Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Thu, 10 Apr 2025 18:54:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=9C=80=E8=BD=AC=E5=8C=96?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kbase_py/fileCon.py | 12 +++++++----- kbase_py/im_ws.py | 12 ++++++++++++ kbase_py/saw-ai-py.json | 3 ++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/kbase_py/fileCon.py b/kbase_py/fileCon.py index fca1c5b..45317e8 100644 --- a/kbase_py/fileCon.py +++ b/kbase_py/fileCon.py @@ -88,9 +88,11 @@ def get_file(): def get_file_add_convert(): file_list = get_file() if file_list: + s = {"epub","txt","docx","pdf","doc", "go", "c", "cpp", "java", "py", "js", "html", "css", "json", "xml", "yaml", "md"} for file in file_list: #文件类型是否允许 - if file["FileStoreName"].endswith(".txt") or file["FileStoreName"].endswith(".docx") or file["FileStoreName"].endswith(".pdf") or file["FileStoreName"].endswith(".epub"): + fileType = file["FileStoreName"].split(".")[-1] + if fileType in s: print("文件类型允许") else: print("文件类型不允许:", file["FileStoreName"]) @@ -100,11 +102,11 @@ def get_file_add_convert(): text = fileBase.get_file_content(file["FileStoreName"]) if text is None: print("文件内容获取失败") - return None + continue print("文件内容长度:", len(text)) #将文件内容上传 print(create_file_content(file["ID"], text)) - break + #break else: print("未能获取文件列表") @@ -129,5 +131,5 @@ def get_Kbase_server_id(): print(f"请求失败,状态码: {response.status_code}, 错误信息: {response.text}") return None -if __name__ == "__main__": - get_file_add_convert() \ No newline at end of file +# if __name__ == "__main__": +# get_file_add_convert() \ No newline at end of file diff --git a/kbase_py/im_ws.py b/kbase_py/im_ws.py index 6c857bc..00680fb 100644 --- a/kbase_py/im_ws.py +++ b/kbase_py/im_ws.py @@ -3,6 +3,7 @@ import time import json import fileChroma import threading +import fileCon config = {} stop_event = False @@ -92,6 +93,14 @@ def input_listener(ws): ws.close() break +def sfile_content(): + #每10秒获取转换一次 + while True: + time.sleep(10) + # 文件内容转换 + fileCon.get_file_add_convert() + if stop_event: + break if __name__ == "__main__": config = readConfig() @@ -109,6 +118,9 @@ if __name__ == "__main__": input_thread = threading.Thread(target=input_listener, args=(ws,)) input_thread.start() + if config["file_convert"]: + file_thread = threading.Thread(target=sfile_content) + file_thread.start() # 运行 WebSocket 连接 ws.run_forever() \ No newline at end of file diff --git a/kbase_py/saw-ai-py.json b/kbase_py/saw-ai-py.json index 5f40491..5217671 100644 --- a/kbase_py/saw-ai-py.json +++ b/kbase_py/saw-ai-py.json @@ -5,5 +5,6 @@ "ws_retry_delay": 1, "kbase_info": {"vfdbvd":{"1":true,"collection_name":""}}, "redis_url": "localhost:6379", - "redis_db": 0 + "redis_db": 0, + "file_convert": false } \ No newline at end of file