跳到主要内容
Jupyter Notebook(曾用名 IPython Notebook)是一个基于网络的交互式计算环境,用于创建 notebook 文档。
本 notebook 介绍了如何将 Jupyter notebook (.ipynb) 文件中的数据加载为 LangChain 适用的格式。
from langchain_community.document_loaders import NotebookLoader
loader = NotebookLoader(
    "example_data/notebook.ipynb",
    include_outputs=True,
    max_output_length=20,
    remove_newline=True,
)
NotebookLoader.load() 方法将 .ipynb notebook 文件加载到一个 Document 对象中。 参数:
  • include_outputs (bool):是否在最终的文档中包含单元格的输出(默认为 False)。
  • max_output_length (int):每个单元格输出所包含的最大字符数(默认为 10)。
  • remove_newline (bool):是否从单元格的源代码和输出中移除换行符(默认为 False)。
  • traceback (bool):是否包含完整的追溯信息(默认为 False)。
loader.load()
[Document(page_content='\'markdown\' cell: \'[\'# Notebook\', \'\', \'This notebook covers how to load data from an .html notebook into a format suitable by LangChain.\']\'\n\n \'code\' cell: \'[\'from langchain_community.document_loaders import NotebookLoader\']\'\n\n \'code\' cell: \'[\'loader = NotebookLoader("example_data/notebook.html")\']\'\n\n \'markdown\' cell: \'[\'`NotebookLoader.load()` loads the `.html` notebook file into a [`Document`](https://reference.langchain.org.cn/python/langchain_core/documents/#langchain_core.documents.base.Document) object.\', \'\', \'**Parameters**:\', \'\', \'* `include_outputs` (bool): whether to include cell outputs in the resulting document (default is False).\', \'* `max_output_length` (int): the maximum number of characters to include from each cell output (default is 10).\', \'* `remove_newline` (bool): whether to remove newline characters from the cell sources and outputs (default is False).\', \'* `traceback` (bool): whether to include full traceback (default is False).\']\'\n\n \'code\' cell: \'[\'loader.load(include_outputs=True, max_output_length=20, remove_newline=True)\']\'\n\n', metadata={'source': 'example_data/notebook.html'})]

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.