AS AgentScopeAPI 手册 / API Reference
类class agentscope.rag

TextParser

class TextParser(ParserBase)
源码Source agentscope/rag/_parser/_text.py:10–125

文本解析器,把私有文档转化为可检索的知识。位于 agentscope.rag 包,继承自 ParserBase。核心成员包括 supported_extensions、parse。

Reads the entire file as UTF-8 text and returns a single :class:Section. No internal boundaries are inferred — the file is treated as one unstructured blob, leaving all splitting to a downstream :class:~agentscope.rag.ChunkerBase.

Supports a fixed set of standard text-based IANA media types (text/plain, text/markdown, text/csv, …). Use TextParser.supported_media_types to enumerate them.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(encoding: str = 'utf-8') -> None
初始化 `TextParser` 实例。
Initialize the text parser.

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
supported_media_typeslist[str]
`supported_media_types` 字段。
['text/plain', 'text/markdown', 'text/csv', 'text/html', 'text/x-rst', 'application/json', 'application/xml', 'application/x-yaml']

方法摘要Method Summary

方法Method说明Description
def supported_extensions() -> list[str]
返回 `supported_extensions` 结果。
Return the human-friendly text extensions.
async def parse(file: bytes | str, filename: str) -> list[Section]async
执行解析相关操作。
Read the file as text and return a single :class:`Section`.

构造器详情Constructor Detail

TextParser

def __init__(encoding: str = 'utf-8') -> None

初始化 TextParser 实例。

Initialize the text parser.

参数Parameters
名称Name类型Type说明Description
encoding默认default 'utf-8'strencoding(类型 `str`)。The text encoding used to decode the file bytes.
源码Source agentscope/rag/_parser/_text.py:60–67

属性详情Attribute Detail

supported_media_types

list[str] = ['text/plain', 'text/markdown', 'text/csv', 'text/html', 'text/x-rst', 'application/json', 'application/xml', 'application/x-yaml']

supported_media_types 字段。声明为 list[str]。

The supported media types field.

源码Source agentscope/rag/_parser/_text.py:23

方法详情Method Detail

supported_extensions

def supported_extensions() -> list[str]

返回 supported_extensions 结果。

Override the base reverse-lookup because :func:mimetypes.guess_all_extensions returns a long tail of developer-tool extensions for text/plain (.bat / .c / .pl / .ksh / …) that have no place in a KB file picker, and returns the empty list for application/x-yaml.

返回Returns list[str]
返回str列表。Returns a list of str.
源码Source agentscope/rag/_parser/_text.py:36–58

parse

async def parse(file: bytes | str, filename: str) -> list[Section]
async

执行解析相关操作。

Read the file as text and return a single :class:Section.

参数Parameters
名称Name类型Type说明Description
filebytes | str文件(类型 `bytes | str`)。The file content. `bytes` is decoded with the configured encoding. `str` is disambiguated at runtime: if it names an existing file on disk the file is read and decoded; otherwise it is used verbatim as pre-decoded text — letting local-mode callers skip the encode → decode round trip.
filenamestrfilename(类型 `str`)。The source filename, copied verbatim into :attr:`Section.source`.
返回Returns list[Section]
返回Section列表。`list[Section]`:
异常Raises
  • 可能抛出 `Exception`。`ValueError`: If the bytes cannot be decoded with the
  • 可能抛出 `Exception`。configured encoding.
源码Source agentscope/rag/_parser/_text.py:69–125
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.