From 969afef5234d9042ed89c41275f4f84b819ff74e Mon Sep 17 00:00:00 2001 From: Jordan Frazier <122494242+jordanrfrazier@users.noreply.github.com> Date: Thu, 3 Jul 2025 07:10:41 -0700 Subject: [PATCH] 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 --- .../base/langflow/base/data/docling_utils.py | 6 +++++- .../docling/export_docling_document.py | 19 +++++++++++++++++++ .../base/langflow/services/auth/utils.py | 9 ++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/backend/base/langflow/base/data/docling_utils.py b/src/backend/base/langflow/base/data/docling_utils.py index d954e6926..1d19ff252 100644 --- a/src/backend/base/langflow/base/data/docling_utils.py +++ b/src/backend/base/langflow/base/data/docling_utils.py @@ -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: diff --git a/src/backend/base/langflow/components/docling/export_docling_document.py b/src/backend/base/langflow/components/docling/export_docling_document.py index 509127f80..5f181e8fe 100644 --- a/src/backend/base/langflow/components/docling/export_docling_document.py +++ b/src/backend/base/langflow/components/docling/export_docling_document.py @@ -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) diff --git a/src/backend/base/langflow/services/auth/utils.py b/src/backend/base/langflow/services/auth/utils.py index 5aad2b976..960afe3c6 100644 --- a/src/backend/base/langflow/services/auth/utils.py +++ b/src/backend/base/langflow/services/auth/utils.py @@ -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: