类class
agentscope.ragPPTParser
class PPTParser(ParserBase)
源码Source
agentscope/rag/_parser/_ppt.py:130–393用于PowerPoint.pptx文件的解析器。位于 agentscope.rag 包,继承自 ParserBase。核心成员包括 supported_extensions、parse。
Slide order is preserved. Within a slide, shapes are visited in document order and grouped into a minimum number of sections:
- Text shapes and table shapes contribute to one running
text section. When
separate_table=Truea table closes the running section and starts a new one of its own. - Picture shapes emit a standalone :class:
Sectionwhosecontentis a :class:DataBlockholding the base64-encoded image bytes.
slide_prefix / slide_suffix are wrapped around each
slide's text content (the prefix is prepended to the slide's
first text section, the suffix is appended to its last text
section). Use None on either to disable wrapping.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
def __init__(include_image: bool = True, separate_table: bool = False, table_format: Literal['markdown', 'json'] = 'mar… | 初始化 `PPTParser` 实例。 Initialize the PowerPoint parser. |
属性摘要Attribute Summary
| 属性Attribute | 类型Type | 说明Description | 值Value |
|---|---|---|---|
supported_media_types | list[str] | `supported_media_types` 字段。 | ['application/vnd.openxmlformats-officedocument.presentationml.presentation'] |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
def supported_extensions() -> list[str] | 返回 `supported_extensions` 结果。 Return ``[".pptx"]`` — the only format ``python-pptx`` reads. |
async def parse(file: bytes | str, filename: str) -> list[Section]async | 执行解析相关操作。 Parse a PPTX file into a list of :class:`Section` objects. |
构造器详情Constructor Detail
PPTParser
def __init__(include_image: bool = True, separate_table: bool = False, table_format: Literal['markdown', 'json'] = 'markdown', slide_prefix: str | None = '<slide index={index}>', slide_suffix: str | None = '</slide>') -> None
初始化 PPTParser 实例。
Initialize the PowerPoint parser.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
include_image默认default True | bool | include 图像(类型 `bool`)。When `True`, picture shapes are emitted as :class:`DataBlock` sections. Set to `False` to keep a text-only index. |
separate_table默认default False | bool | separate table(类型 `bool`)。When `True`, each table becomes its own text section, never merged with surrounding text. table_format (`Literal["markdown", "json"]`, defaults to `"markdown"`): How to render tables. `"markdown"` uses pipe-table syntax, escaping pipes and rendering cell line breaks as ` `; `"json"` emits a JSON array prefixed with a ` ` marker and preserves extracted cell strings without Markdown rendering. slide_prefix (`str | None`, defaults to `" "`): Prepended to the first text section of each slide. Supports the `{index}` placeholder (starting at 1). Use `None` to disable. |
table_format默认default 'markdown' | Literal['markdown', 'json'] | table 格式(类型 `Literal['markdown', 'json']`)。The table format. |
slide_prefix默认default '<slide index={index}>' | str | None | slide prefix(类型 `str | None`)。The slide prefix. |
slide_suffix默认default '</slide>' | str | None | slide suffix(类型 `str | None`)。Appended to the last text section of each slide. Use `None` to disable. |
- 可能抛出 `Exception`。`ValueError`: If `table_format` is not one of
- 可能抛出 `Exception`。`"markdown"` / `"json"`.
源码Source
agentscope/rag/_parser/_ppt.py:160–207属性详情Attribute Detail
supported_media_types
list[str] = ['application/vnd.openxmlformats-officedocument.presentationml.presentation']supported_media_types 字段。声明为 list[str]。
The supported media types field.
源码Source
agentscope/rag/_parser/_ppt.py:149方法详情Method Detail
supported_extensions
def supported_extensions() -> list[str]
返回 supported_extensions 结果。
Return [".pptx"] — the only format python-pptx reads.
list[str]
返回str列表。Returns a list of str.
源码Source
agentscope/rag/_parser/_ppt.py:155–158parse
async def parse(file: bytes | str, filename: str) -> list[Section]
async
执行解析相关操作。
Parse a PPTX file into a list of :class:Section objects.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
file | bytes | str | 文件(类型 `bytes | str`)。Either the raw PPTX bytes, or a filesystem path to the PPTX file. |
filename | str | filename(类型 `str`)。The source filename, copied into each Section's :attr:`Section.source`. |
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:`python-pptx` is not installed.
- 可能抛出 `Exception`。`ValueError`: If the bytes cannot be parsed.
源码Source
agentscope/rag/_parser/_ppt.py:209–268