feat(pre_process_file):解决hxops上传excel行截断的问题,由markdown换为命中更好的key=value的方式;dify同步custom;行间\n\n,数据行单独成块;
This commit is contained in:
1 parent
a18a07ef1a
commit
67d08924a4
25 files changed
+655
-25
No files matched your search
@@ -52,6 +52,42 @@ def _find_generated_preview_markdown(output_root: Path) -> Path | None:
|
||||
return candidates[0]
|
||||
|
||||
|
||||
def _find_generated_chunks_jsonl(output_root: Path) -> Path | None:
|
||||
candidates = [path for path in output_root.rglob('04_chunks.jsonl') if path.is_file()]
|
||||
if not candidates:
|
||||
return None
|
||||
candidates.sort(key=lambda item: len(item.parts))
|
||||
return candidates[0]
|
||||
|
||||
|
||||
def _count_jsonl_lines(path: Path) -> int:
|
||||
count = 0
|
||||
with path.open(encoding='utf-8', errors='ignore') as handle:
|
||||
for line in handle:
|
||||
if line.strip():
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
def _persist_debug_chunks(output_root: Path, target_dir: Path) -> tuple[str | None, int | None]:
|
||||
"""Copy edkb chunk artifacts into the KB version directory for local debugging."""
|
||||
chunks_source = _find_generated_chunks_jsonl(output_root)
|
||||
if not chunks_source or not chunks_source.exists():
|
||||
return None, None
|
||||
|
||||
chunks_target = target_dir / '04_chunks.jsonl'
|
||||
shutil.copy2(chunks_source, chunks_target)
|
||||
|
||||
chunks_dir_source = chunks_source.parent / 'chunks'
|
||||
chunks_dir_target = target_dir / 'chunks'
|
||||
if chunks_dir_source.is_dir():
|
||||
if chunks_dir_target.exists():
|
||||
shutil.rmtree(chunks_dir_target)
|
||||
shutil.copytree(chunks_dir_source, chunks_dir_target)
|
||||
|
||||
return str(chunks_target), _count_jsonl_lines(chunks_target)
|
||||
|
||||
|
||||
def _rewrite_preview_markdown_if_needed(preview_path: Path, target_dir: Path) -> None:
|
||||
content = preview_path.read_text(encoding='utf-8', errors='ignore')
|
||||
if 'data:image/' not in content:
|
||||
@@ -141,10 +177,13 @@ def build_clean_result(source_path: Path, target_dir: Path) -> dict:
|
||||
shutil.copytree(preview_images_dir, target_preview_images_dir)
|
||||
_rewrite_preview_markdown_if_needed(preview_path, target_dir)
|
||||
content = cleaned_path.read_text(encoding='utf-8', errors='ignore')
|
||||
chunks_file_path, chunks_count = _persist_debug_chunks(output_dir, target_dir)
|
||||
|
||||
return {
|
||||
'mode': 'edkb_system',
|
||||
'cleaned_file_path': str(cleaned_path),
|
||||
'cleaned_preview_path': str(preview_path),
|
||||
'word_count': len(content.split()),
|
||||
'chunks_file_path': chunks_file_path,
|
||||
'chunks_count': chunks_count,
|
||||
}
|
||||
Reference in new issue
Block a user