|
|
|
@@ -452,7 +452,7 @@ def get_image(image_id): |
|
|
|
@login_required
|
|
|
|
@validate_request("conversation_id")
|
|
|
|
def upload_and_parse():
|
|
|
|
req = request.json
|
|
|
|
from rag.app import presentation, picture, naive, audio, email
|
|
|
|
if 'file' not in request.files:
|
|
|
|
return get_json_result(
|
|
|
|
data=False, retmsg='No file part!', retcode=RetCode.ARGUMENT_ERROR)
|
|
|
|
@@ -463,7 +463,7 @@ def upload_and_parse(): |
|
|
|
return get_json_result(
|
|
|
|
data=False, retmsg='No file selected!', retcode=RetCode.ARGUMENT_ERROR)
|
|
|
|
|
|
|
|
e, conv = ConversationService.get_by_id(req["conversation_id"])
|
|
|
|
e, conv = ConversationService.get_by_id(request.form.get("conversation_id"))
|
|
|
|
if not e:
|
|
|
|
return get_data_error_result(retmsg="Conversation not found!")
|
|
|
|
e, dia = DialogService.get_by_id(conv.dialog_id)
|
|
|
|
@@ -487,6 +487,12 @@ def upload_and_parse(): |
|
|
|
def dummy(prog=None, msg=""):
|
|
|
|
pass
|
|
|
|
|
|
|
|
FACTORY = {
|
|
|
|
ParserType.PRESENTATION.value: presentation,
|
|
|
|
ParserType.PICTURE.value: picture,
|
|
|
|
ParserType.AUDIO.value: audio,
|
|
|
|
ParserType.EMAIL.value: email
|
|
|
|
}
|
|
|
|
parser_config = {"chunk_token_num": 4096, "delimiter": "\n!?;。;!?", "layout_recognize": False}
|
|
|
|
exe = ThreadPoolExecutor(max_workers=12)
|
|
|
|
threads = []
|
|
|
|
@@ -497,7 +503,7 @@ def upload_and_parse(): |
|
|
|
"from_page": 0,
|
|
|
|
"to_page": 100000
|
|
|
|
}
|
|
|
|
threads.append(exe.submit(naive.chunk, d["name"], blob, **kwargs))
|
|
|
|
threads.append(exe.submit(FACTORY.get(d["parser_id"], naive).chunk, d["name"], blob, **kwargs))
|
|
|
|
|
|
|
|
for (docinfo,_), th in zip(files, threads):
|
|
|
|
docs = []
|
|
|
|
@@ -550,7 +556,7 @@ def upload_and_parse(): |
|
|
|
for doc_id in docids:
|
|
|
|
cks = [c for c in docs if c["doc_id"] == doc_id]
|
|
|
|
|
|
|
|
if parser_ids[doc_id] != ParserType.PICTURE.value:
|
|
|
|
if False and parser_ids[doc_id] != ParserType.PICTURE.value:
|
|
|
|
mindmap = MindMapExtractor(llm_bdl)
|
|
|
|
try:
|
|
|
|
mind_map = json.dumps(mindmap([c["content_with_weight"] for c in docs if c["doc_id"] == doc_id]).output, ensure_ascii=False, indent=2)
|
|
|
|
@@ -564,7 +570,7 @@ def upload_and_parse(): |
|
|
|
except Exception as e:
|
|
|
|
stat_logger.error("Mind map generation error:", traceback.format_exc())
|
|
|
|
|
|
|
|
vects = embedding(doc_id, cks)
|
|
|
|
vects = embedding(doc_id, [c["content_with_weight"] for c in cks])
|
|
|
|
assert len(cks) == len(vects)
|
|
|
|
for i, d in enumerate(cks):
|
|
|
|
v = vects[i]
|
|
|
|
@@ -575,4 +581,4 @@ def upload_and_parse(): |
|
|
|
DocumentService.increment_chunk_num(
|
|
|
|
doc_id, kb.id, token_counts[doc_id], chunk_counts[doc_id], 0)
|
|
|
|
|
|
|
|
return get_json_result(data=[d["id"] for d in files])
|
|
|
|
return get_json_result(data=[d["id"] for d,_ in files])
|