总结链---对大文本通过拆分总结摘要
from langchain.chains import load_summarize_chain from langchain_community.document_loaders import TextLoader #文本加载器 from langchain_community.llms.ollama import Ollama from langchain_text_splitters import RecursiveCharacterTextSplitter llm = Ollama(model="qwen:7b") loader = TextLoader("/home/cmcc/server/file/测试文档.txt", encoding="utf-8") documents = loader.load() #对文本进行循环分割 chunk_size每一段文本大小, chunk_overlap 重复文本大小 (RecursiveCharacterTextSplitter 分离器) text_splitter = RecursiveCharacterTextSplitter(chunk_size=700, chunk_overlap=50) #将你的文档拆分为文本 texts = text_splitter.split_documents(documents) chain = load_summarize_chain(llm, chain_type="map_reduce", verbose=True) chain.run(texts)