在深入研究程式碼之前,必須安裝必要的軟體包以確保一切順利運作。您可以透過在終端機中執行以下命令來完成此操作:
pip install langchain_community pip install pypdf
from langchain_community.document_loaders import PyPDFLoader from langchain.text_splitter import RecursiveCharacterTextSplitter # Load the PDF file from the specified path. FILE_PATH = "c:/work/Test01.pdf" loader = PyPDFLoader(file_path=FILE_PATH) # Load the entire PDF into a list of documents text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50) documents = loader.load_and_split(text_splitter) for i in range(len(documents)): print(documents[i].page_content + "\n")```
以上是使用 Langchain 將整個 PDF 載入到文件清單中的簡單指南的詳細內容。更多資訊請關注PHP中文網其他相關文章!