Spaces:
Sleeping
Sleeping
Update rag_engine.py
Browse files8 unmodified lines910111213141516171819202122232425265 unmodified lines32333435363738394041428 unmodified lines)from langsmith import traceablefrom langsmith.run_helpers import set_run_metadatadef build_rag_chunks_from_file(file, doc_type_val: str) -> List[Dict]:"""从上传的文件构建 RAG chunk 列表(session 级别)。- 支持 .docx 和 .pdf- 复用 syllabus_utils 里的解析函数,把文档切成一系列文本块- 对每个非空文本块做 embedding,存成 {"text": str, "embedding": List[float]}当前 doc_type_val 主要用于未来扩展(不同类型文件可采用不同切块策略),这里先不区分,统一按段落/块处理。"""if file is None:return []5 unmodified linesext = os.path.splitext(file_path)[1].lower()try:# 1) 解析文件 → 得到一组文本块if ext == ".docx":texts = parse_syllabus_docx(file_path)elif ext == ".pdf":texts = parse_syllabus_pdf(file_path)else:print(f"[RAG] unsupported file type for RAG: {ext}")return []8 unmodified lines910111213141516171819202122235 unmodified lines293031323334353637383940418 unmodified lines)from langsmith import traceablefrom langsmith.run_helpers import set_run_metadatafrom syllabus_utils import parse_syllabus_docx, parse_syllabus_pdf, parse_pptx_slidesdef build_rag_chunks_from_file(file, doc_type_val: str) -> List[Dict]:"""从上传的文件构建 RAG chunk 列表(session 级别)。- 支持 .docx / .pdf / .pptx- 复用 syllabus_utils 里的解析函数,把文档切成一系列文本块- 对每个非空文本块做 embedding,存成 {"text": str, "embedding": List[float]}"""if file is None:return []5 unmodified linesext = os.path.splitext(file_path)[1].lower()try:# 1) 解析文件 → 文本块列表if ext == ".docx":texts = parse_syllabus_docx(file_path)elif ext == ".pdf":texts = parse_syllabus_pdf(file_path)elif ext == ".pptx":texts = parse_pptx_slides(file_path)else:print(f"[RAG] unsupported file type for RAG: {ext}")return []
rag_engine.py+5-6