ref: improve docling template updates and error message (#8837)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
Jordan Frazier 2025-07-03 07:10:41 -07:00 committed by Gabriel Luiz Freitas Almeida
commit 969afef523
3 changed files with 28 additions and 6 deletions

View file

@ -26,7 +26,11 @@ def extract_docling_documents(data_inputs: Data | list[Data] | DataFrame, doc_ke
if isinstance(data_inputs, Data):
if doc_key not in data_inputs.data:
msg = f"{doc_key} field not available in the input Data"
msg = (
f"'{doc_key}' field not available in the input Data. "
"Check that your input is a DoclingDocument. "
"You can use the Docling component to convert your input to a DoclingDocument."
)
raise TypeError(msg)
documents = [data_inputs.data[doc_key]]
else:

View file

@ -1,3 +1,5 @@
from typing import Any
from docling_core.types.doc import ImageRefMode
from langflow.base.data.docling_utils import extract_docling_documents
@ -27,6 +29,7 @@ class ExportDoclingDocumentComponent(Component):
options=["Markdown", "HTML", "Plaintext", "DocTags"],
info="Select the export format to convert the input.",
value="Markdown",
real_time_refresh=True,
),
DropdownInput(
name="image_mode",
@ -66,6 +69,22 @@ class ExportDoclingDocumentComponent(Component):
Output(display_name="DataFrame", name="dataframe", method="as_dataframe"),
]
def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict:
if field_name == "export_format" and field_value == "Markdown":
build_config["md_image_placeholder"]["show"] = True
build_config["md_page_break_placeholder"]["show"] = True
build_config["image_mode"]["show"] = True
elif field_name == "export_format" and field_value == "HTML":
build_config["md_image_placeholder"]["show"] = False
build_config["md_page_break_placeholder"]["show"] = False
build_config["image_mode"]["show"] = True
elif field_name == "export_format" and field_value in {"Plaintext", "DocTags"}:
build_config["md_image_placeholder"]["show"] = False
build_config["md_page_break_placeholder"]["show"] = False
build_config["image_mode"]["show"] = False
return build_config
def export_document(self) -> list[Data]:
documents = extract_docling_documents(self.data_inputs, self.doc_key)

View file

@ -60,11 +60,10 @@ async def api_key_security(
result = await get_user_by_username(db, settings_service.auth_settings.SUPERUSER)
logger.warning(AUTO_LOGIN_WARNING)
return UserRead.model_validate(result, from_attributes=True)
else:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail=AUTO_LOGIN_ERROR,
)
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail=AUTO_LOGIN_ERROR,
)
result = await check_key(db, query_param or header_param)
elif not query_param and not header_param: