Skip to content

Commit c4693fa

Browse files
authored
fix: support rst and adoc knowledge uploads (#8255)
1 parent 7a9fb33 commit c4693fa

6 files changed

Lines changed: 16 additions & 5 deletions

File tree

astrbot/core/knowledge_base/parsers/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
async def select_parser(ext: str) -> BaseParser:
5-
if ext in {".md", ".txt", ".markdown", ".xlsx", ".docx", ".xls"}:
5+
if ext in {".md", ".txt", ".markdown", ".rst", ".adoc", ".xlsx", ".docx", ".xls"}:
66
from .markitdown_parser import MarkitdownParser
77

88
return MarkitdownParser()

dashboard/src/i18n/locales/en-US/features/knowledge-base/detail.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"title": "Upload Document",
5050
"selectFile": "Select File",
5151
"dropzone": "Drop files here or click to select",
52-
"supportedFormats": "Supported formats: .txt, .md, .pdf, .docx, .epub, .xls, .xlsx",
52+
"supportedFormats": "Supported formats: .txt, .md, .markdown, .rst, .adoc, .pdf, .docx, .epub, .xls, .xlsx",
5353
"maxSize": "Max file size: 128MB",
5454
"chunkSettings": "Chunk Settings",
5555
"batchSettings": "Batch Settings",

dashboard/src/i18n/locales/ru-RU/features/knowledge-base/detail.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"title": "Добавление контента",
5050
"selectFile": "Файл",
5151
"dropzone": "Нажмите или перетащите файл сюда",
52-
"supportedFormats": "Форматы: .txt, .md, .pdf, .docx, .epub, .xls, .xlsx",
52+
"supportedFormats": "Форматы: .txt, .md, .markdown, .rst, .adoc, .pdf, .docx, .epub, .xls, .xlsx",
5353
"maxSize": "Максимум: 128MB",
5454
"chunkSettings": "Фрагментация",
5555
"batchSettings": "Пакетная обработка",

dashboard/src/i18n/locales/zh-CN/features/knowledge-base/detail.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"title": "上传文档",
5050
"selectFile": "选择文件",
5151
"dropzone": "拖放文件到这里或点击选择",
52-
"supportedFormats": "支持的格式: .txt, .md, .pdf, .docx, .epub, .xls, .xlsx",
52+
"supportedFormats": "支持的格式: .txt, .md, .markdown, .rst, .adoc, .pdf, .docx, .epub, .xls, .xlsx",
5353
"maxSize": "最大文件大小: 128MB",
5454
"chunkSettings": "分块设置",
5555
"batchSettings": "批处理设置",

dashboard/src/views/knowledge-base/components/DocumentsTab.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<p class="text-caption text-medium-emphasis mt-2">{{ t('upload.supportedFormats') }}</p>
8686
<p class="text-caption text-medium-emphasis">{{ t('upload.maxSize') }}</p>
8787
<p class="text-caption text-medium-emphasis">最多可上传 10 个文件</p>
88-
<input ref="fileInput" type="file" multiple hidden accept=".txt,.md,.pdf,.docx,.epub,.xls,.xlsx"
88+
<input ref="fileInput" type="file" multiple hidden accept=".txt,.md,.markdown,.rst,.adoc,.pdf,.docx,.epub,.xls,.xlsx"
8989
@change="handleFileSelect" />
9090
</div>
9191

@@ -709,6 +709,7 @@ const getFileIcon = (fileType: string) => {
709709
const type = fileType?.toLowerCase() || ''
710710
if (type.includes('pdf')) return 'mdi-file-pdf-box'
711711
if (type.includes('epub')) return 'mdi-book-open-page-variant'
712+
if (type.includes('rst') || type.includes('adoc')) return 'mdi-file-document-outline'
712713
if (type.includes('md') || type.includes('markdown')) return 'mdi-language-markdown'
713714
if (type.includes('txt')) return 'mdi-file-document-outline'
714715
if (type.includes('url')) return 'mdi-link-variant'
@@ -719,6 +720,7 @@ const getFileColor = (fileType: string) => {
719720
const type = fileType?.toLowerCase() || ''
720721
if (type.includes('pdf')) return 'error'
721722
if (type.includes('epub')) return 'warning'
723+
if (type.includes('rst') || type.includes('adoc')) return 'success'
722724
if (type.includes('md')) return 'info'
723725
if (type.includes('txt')) return 'success'
724726
if (type.includes('url')) return 'primary'

tests/test_epub_parser.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77

88
from astrbot.core.knowledge_base.parsers.epub_parser import EpubParser
9+
from astrbot.core.knowledge_base.parsers.markitdown_parser import MarkitdownParser
910
from astrbot.core.knowledge_base.parsers.util import select_parser
1011

1112

@@ -174,6 +175,14 @@ async def test_select_parser_supports_epub():
174175
assert isinstance(parser, EpubParser)
175176

176177

178+
@pytest.mark.asyncio
179+
@pytest.mark.parametrize("ext", [".rst", ".adoc"])
180+
async def test_select_parser_supports_text_markup_formats(ext):
181+
parser = await select_parser(ext)
182+
183+
assert isinstance(parser, MarkitdownParser)
184+
185+
177186
@pytest.mark.asyncio
178187
async def test_epub_parser_reads_spine_order_as_text():
179188
result = await EpubParser().parse(_make_epub_bytes(), "book.epub")

0 commit comments

Comments
 (0)