You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.6 KiB

4 weeks ago
import asyncio
4 weeks ago
import os
import shutil
4 weeks ago
from raganything import RAGAnything, RAGAnythingConfig
4 weeks ago
from Util.RagUtil import create_llm_model_func, create_vision_model_func, create_embedding_func
4 weeks ago
async def main():
4 weeks ago
# 要处理的文件路径
3 weeks ago
file_path = "static/Txt/吉林动画学院一览表.pdf"
4 weeks ago
# 索引生成目录
3 weeks ago
WORKING_DIR = "./Topic/DongHua"
4 weeks ago
# 删除output目录下的所有文件
output_dir="./output"
shutil.rmtree(output_dir, ignore_errors=True)
os.makedirs(output_dir, exist_ok=True)
# 删除WORKING_DIR下的所有文件
shutil.rmtree(WORKING_DIR, ignore_errors=True)
os.makedirs(WORKING_DIR, exist_ok=True)
4 weeks ago
4 weeks ago
# 指定最终的索引生成目录,启动索引生成
4 weeks ago
config = RAGAnythingConfig(
4 weeks ago
working_dir=WORKING_DIR,
4 weeks ago
mineru_parse_method="auto",
enable_image_processing=True,
enable_table_processing=True,
enable_equation_processing=True,
)
4 weeks ago
# 自定义的大模型函数
4 weeks ago
llm_model_func = create_llm_model_func()
4 weeks ago
# 自定义的可视模型函数
4 weeks ago
vision_model_func = create_vision_model_func(llm_model_func)
4 weeks ago
# 自定义的嵌入函数
4 weeks ago
embedding_func = create_embedding_func()
4 weeks ago
rag = RAGAnything(
config=config,
llm_model_func=llm_model_func,
vision_model_func=vision_model_func,
embedding_func=embedding_func,
)
await rag.process_document_complete(
4 weeks ago
file_path=file_path,
4 weeks ago
output_dir=output_dir,
4 weeks ago
parse_method="auto"
)
4 weeks ago
print("文档解析索引完成!")
4 weeks ago
4 weeks ago
if __name__ == "__main__":
asyncio.run(main())