Skip to content

Commit d4030a8

Browse files
committed
refac
1 parent 1f0948b commit d4030a8

5 files changed

Lines changed: 41 additions & 2 deletions

File tree

backend/open_webui/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,12 @@ def reachable(host: str, port: int) -> bool:
11091109
mineru_params,
11101110
)
11111111

1112+
MINERU_FILE_EXTENSIONS = ConfigVar(
1113+
'MINERU_FILE_EXTENSIONS',
1114+
'rag.mineru_file_extensions',
1115+
[ext.strip() for ext in os.getenv('MINERU_FILE_EXTENSIONS', 'pdf').split(',') if ext.strip()],
1116+
)
1117+
11121118
EXTERNAL_DOCUMENT_LOADER_URL = ConfigVar(
11131119
'EXTERNAL_DOCUMENT_LOADER_URL',
11141120
'rag.external_document_loader_url',

backend/open_webui/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
MINERU_API_MODE,
282282
MINERU_API_TIMEOUT,
283283
MINERU_API_URL,
284+
MINERU_FILE_EXTENSIONS,
284285
MINERU_PARAMS,
285286
MISTRAL_OCR_API_BASE_URL,
286287
MISTRAL_OCR_API_KEY,
@@ -1022,6 +1023,7 @@ async def lifespan(app: FastAPI):
10221023
app.state.config.MINERU_API_KEY = MINERU_API_KEY
10231024
app.state.config.MINERU_API_TIMEOUT = MINERU_API_TIMEOUT
10241025
app.state.config.MINERU_PARAMS = MINERU_PARAMS
1026+
app.state.config.MINERU_FILE_EXTENSIONS = MINERU_FILE_EXTENSIONS
10251027

10261028
app.state.config.TEXT_SPLITTER = RAG_TEXT_SPLITTER
10271029
app.state.config.ENABLE_MARKDOWN_HEADER_TEXT_SPLITTER = ENABLE_MARKDOWN_HEADER_TEXT_SPLITTER

backend/open_webui/retrieval/loaders/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def _get_loader(self, filename: str, file_content_type: str, file_path: str):
371371
azure_credential=DefaultAzureCredential(),
372372
api_model=self.kwargs.get('DOCUMENT_INTELLIGENCE_MODEL'),
373373
)
374-
elif self.engine == 'mineru' and file_ext in ['pdf']: # MinerU currently only supports PDF
374+
elif self.engine == 'mineru' and file_ext in self.kwargs.get('MINERU_FILE_EXTENSIONS', ['pdf']):
375375
mineru_timeout = self.kwargs.get('MINERU_API_TIMEOUT', 300)
376376
if mineru_timeout:
377377
try:

backend/open_webui/routers/retrieval.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ async def get_rag_config(request: Request, user=Depends(get_admin_user)):
466466
'MINERU_API_KEY': request.app.state.config.MINERU_API_KEY,
467467
'MINERU_API_TIMEOUT': request.app.state.config.MINERU_API_TIMEOUT,
468468
'MINERU_PARAMS': request.app.state.config.MINERU_PARAMS,
469+
'MINERU_FILE_EXTENSIONS': request.app.state.config.MINERU_FILE_EXTENSIONS,
469470
# Reranking settings
470471
'RAG_RERANKING_MODEL': request.app.state.config.RAG_RERANKING_MODEL,
471472
'RAG_RERANKING_ENGINE': request.app.state.config.RAG_RERANKING_ENGINE,
@@ -681,6 +682,7 @@ class ConfigForm(BaseModel):
681682
MINERU_API_KEY: str | None = None
682683
MINERU_API_TIMEOUT: str | None = None
683684
MINERU_PARAMS: dict | None = None
685+
MINERU_FILE_EXTENSIONS: list[str] | None = None
684686

685687
# Reranking settings
686688
RAG_RERANKING_MODEL: str | None = None
@@ -904,6 +906,11 @@ async def update_rag_config(request: Request, form_data: ConfigForm, user=Depend
904906
request.app.state.config.MINERU_PARAMS = (
905907
form_data.MINERU_PARAMS if form_data.MINERU_PARAMS is not None else request.app.state.config.MINERU_PARAMS
906908
)
909+
request.app.state.config.MINERU_FILE_EXTENSIONS = (
910+
form_data.MINERU_FILE_EXTENSIONS
911+
if form_data.MINERU_FILE_EXTENSIONS is not None
912+
else request.app.state.config.MINERU_FILE_EXTENSIONS
913+
)
907914

908915
# Reranking settings
909916
if request.app.state.config.RAG_RERANKING_ENGINE == '':

src/lib/components/admin/Settings/Documents.svelte

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@
244244
MINERU_PARAMS:
245245
typeof RAGConfig.MINERU_PARAMS === 'string' && RAGConfig.MINERU_PARAMS.trim() !== ''
246246
? JSON.parse(RAGConfig.MINERU_PARAMS)
247-
: {}
247+
: {},
248+
MINERU_FILE_EXTENSIONS: RAGConfig.MINERU_FILE_EXTENSIONS.split(',')
249+
.map((ext) => ext.trim())
250+
.filter((ext) => ext !== '')
248251
});
249252
dispatch('save');
250253
};
@@ -286,6 +289,8 @@
286289
? JSON.stringify(config.MINERU_PARAMS ?? {}, null, 2)
287290
: config.MINERU_PARAMS;
288291
292+
config.MINERU_FILE_EXTENSIONS = (config?.MINERU_FILE_EXTENSIONS ?? ['pdf']).join(', ');
293+
289294
RAGConfig = config;
290295
});
291296
</script>
@@ -763,6 +768,25 @@
763768
/>
764769
</div>
765770
</div>
771+
772+
<!-- File Extensions -->
773+
<div class="flex flex-col justify-between w-full mt-2">
774+
<div class="text-xs font-medium mb-1">
775+
<Tooltip
776+
content={$i18n.t(
777+
'Comma-separated list of file extensions MinerU will handle (e.g. pdf, docx, pptx, xlsx)'
778+
)}
779+
placement="top-start"
780+
>
781+
{$i18n.t('File Extensions')}
782+
</Tooltip>
783+
</div>
784+
<input
785+
class="flex-1 w-full text-sm bg-transparent outline-hidden"
786+
placeholder={$i18n.t('pdf, docx, pptx, xlsx')}
787+
bind:value={RAGConfig.MINERU_FILE_EXTENSIONS}
788+
/>
789+
</div>
766790
{/if}
767791
</div>
768792

0 commit comments

Comments
 (0)