agentscope.ragTextParser
class TextParser(ParserBase)
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_types | list[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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
encoding默认default 'utf-8' | str | encoding(类型 `str`)。The text encoding used to decode the file bytes. |
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.
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.
agentscope/rag/_parser/_text.py:36–58parse
async def parse(file: bytes | str, filename: str) -> list[Section]
执行解析相关操作。
Read the file as text and return a single :class:Section.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
file | bytes | 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. |
filename | str | filename(类型 `str`)。The source filename, copied verbatim into :attr:`Section.source`. |
- 可能抛出 `Exception`。`ValueError`: If the bytes cannot be decoded with the
- 可能抛出 `Exception`。configured encoding.
agentscope/rag/_parser/_text.py:69–125