类class
agentscope.ragPDFParser
class PDFParser(ParserBase)
源码Source
agentscope/rag/_parser/_pdf.py:16–94用于PDF 文件的解析器。位于 agentscope.rag 包,继承自 ParserBase。核心成员包括 supported_extensions、parse。
Returns one :class:Section per page. Empty / image-only pages
still produce a Section (with empty text) so the page → section
correspondence stays exact — downstream chunkers naturally drop
empty content.
Requires :mod:pypdf; install with pip install pypdf (or via
the agentscope[rag] extra).
属性摘要Attribute Summary
| 属性Attribute | 类型Type | 说明Description | 值Value |
|---|---|---|---|
supported_media_types | list[str] | `supported_media_types` 字段。 | ['application/pdf'] |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
def supported_extensions() -> list[str] | 返回规范`.pdf`扩展。 Return the canonical ``.pdf`` extension. |
async def parse(file: bytes | str, filename: str) -> list[Section]async | 执行解析相关操作。 Read the PDF bytes and return one Section per page. |
属性详情Attribute Detail
supported_media_types
list[str] = ['application/pdf']supported_media_types 字段。声明为 list[str]。
The supported media types field.
源码Source
agentscope/rag/_parser/_pdf.py:28方法详情Method Detail
supported_extensions
def supported_extensions() -> list[str]
返回规范.pdf扩展。
Return the canonical .pdf extension.
list[str]
返回str列表。Returns a list of str.
源码Source
agentscope/rag/_parser/_pdf.py:31–33parse
async def parse(file: bytes | str, filename: str) -> list[Section]
async
执行解析相关操作。
Read the PDF bytes and return one Section per page.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
file | bytes | str | 文件(类型 `bytes | str`)。Either the raw PDF bytes, or a filesystem path to the PDF file. |
filename | str | filename(类型 `str`)。The source filename, copied verbatim into each Section's :attr:`Section.source` field. |
list[Section]
返回Section列表。`list[Section]`:
- 可能抛出 `Exception`。`FileNotFoundError`: If `file` is a `str` pointing to
- 可能抛出 `Exception`。a path that does not exist.
- 可能抛出 `Exception`。`ImportError`: If :mod:`pypdf` is not installed.
- 可能抛出 `Exception`。`ValueError`: If the bytes cannot be parsed as PDF.
源码Source
agentscope/rag/_parser/_pdf.py:35–94