feat: support ODT document extraction (#39973)

Co-authored-by: Crazywoola <100913391+crazywoola@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
This commit is contained in:
蓝破碎半圆/破碎蓝调 2026-08-20 13:23:03 +00:00 committed by GitHub
parent 1bb9183af9
commit ccfb47d2c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 69 additions and 0 deletions

View File

@ -36,6 +36,7 @@ _UNSTRUCTURED_DOCUMENT_EXTENSION_BASE: frozenset[str] = frozenset(
"pptx",
"xml",
"epub",
"odt",
)
)
_DEFAULT_DOCUMENT_EXTENSION_BASE: frozenset[str] = frozenset(
@ -53,6 +54,7 @@ _DEFAULT_DOCUMENT_EXTENSION_BASE: frozenset[str] = frozenset(
"csv",
"vtt",
"properties",
"odt",
)
)

View File

@ -441,6 +441,48 @@ def test_extract_text_from_excel_numeric_type_column(mock_excel_file):
assert expected_manual == result
@pytest.mark.parametrize(
("extension", "mime_type", "route_label"),
[
(".odt", "text/plain", "extension"),
(None, "application/vnd.oasis.opendocument.text", "mime_type"),
],
)
def test_extract_text_from_file_routes_odt_inputs_to_graphon_odt_extractor(
document_extractor_node,
extension,
mime_type,
route_label,
):
file = Mock(spec=File)
file.extension = extension
file.mime_type = mime_type
def fake_partition(file_content, *, suffix, unstructured_api_config, load_local_partition, render_element):
assert file_content == b"odt content"
assert suffix == ".odt"
assert unstructured_api_config == document_extractor_node._unstructured_api_config
assert load_local_partition.__name__ == "_load_partition_odt"
assert render_element is not None
return f"extracted through {route_label}"
with (
patch(
"graphon.nodes.document_extractor.node._download_file_content",
return_value=b"odt content",
) as mock_download,
patch("graphon.nodes.document_extractor.node._partition_unstructured_file", side_effect=fake_partition),
):
text = _extract_text_from_file(
document_extractor_node.http_client,
file,
unstructured_api_config=document_extractor_node._unstructured_api_config,
)
assert text == f"extracted through {route_label}"
mock_download.assert_called_once_with(document_extractor_node.http_client, file)
@pytest.mark.parametrize(
("extension", "mime_type"),
[

View File

@ -0,0 +1,25 @@
import importlib
import pytest
import constants
from configs import dify_config
@pytest.mark.parametrize("etl_type", ["SelfHosted", "Unstructured"])
def test_document_extensions_include_odt_for_document_etl_modes(monkeypatch: pytest.MonkeyPatch, etl_type: str) -> None:
original_etl_type = dify_config.ETL_TYPE
original_unstructured_api_url = dify_config.UNSTRUCTURED_API_URL
try:
monkeypatch.setattr(dify_config, "ETL_TYPE", etl_type)
monkeypatch.setattr(dify_config, "UNSTRUCTURED_API_URL", None)
reloaded_constants = importlib.reload(constants)
assert "odt" in reloaded_constants.DOCUMENT_EXTENSIONS
assert "ODT" in reloaded_constants.DOCUMENT_EXTENSIONS
finally:
monkeypatch.setattr(dify_config, "ETL_TYPE", original_etl_type)
monkeypatch.setattr(dify_config, "UNSTRUCTURED_API_URL", original_unstructured_api_url)
importlib.reload(constants)