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:
parent
fe58d69ae7
commit
969afef523
3 changed files with 28 additions and 6 deletions
|
|
@ -26,7 +26,11 @@ def extract_docling_documents(data_inputs: Data | list[Data] | DataFrame, doc_ke
|
||||||
|
|
||||||
if isinstance(data_inputs, Data):
|
if isinstance(data_inputs, Data):
|
||||||
if doc_key not in 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)
|
raise TypeError(msg)
|
||||||
documents = [data_inputs.data[doc_key]]
|
documents = [data_inputs.data[doc_key]]
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from docling_core.types.doc import ImageRefMode
|
from docling_core.types.doc import ImageRefMode
|
||||||
|
|
||||||
from langflow.base.data.docling_utils import extract_docling_documents
|
from langflow.base.data.docling_utils import extract_docling_documents
|
||||||
|
|
@ -27,6 +29,7 @@ class ExportDoclingDocumentComponent(Component):
|
||||||
options=["Markdown", "HTML", "Plaintext", "DocTags"],
|
options=["Markdown", "HTML", "Plaintext", "DocTags"],
|
||||||
info="Select the export format to convert the input.",
|
info="Select the export format to convert the input.",
|
||||||
value="Markdown",
|
value="Markdown",
|
||||||
|
real_time_refresh=True,
|
||||||
),
|
),
|
||||||
DropdownInput(
|
DropdownInput(
|
||||||
name="image_mode",
|
name="image_mode",
|
||||||
|
|
@ -66,6 +69,22 @@ class ExportDoclingDocumentComponent(Component):
|
||||||
Output(display_name="DataFrame", name="dataframe", method="as_dataframe"),
|
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]:
|
def export_document(self) -> list[Data]:
|
||||||
documents = extract_docling_documents(self.data_inputs, self.doc_key)
|
documents = extract_docling_documents(self.data_inputs, self.doc_key)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,11 +60,10 @@ async def api_key_security(
|
||||||
result = await get_user_by_username(db, settings_service.auth_settings.SUPERUSER)
|
result = await get_user_by_username(db, settings_service.auth_settings.SUPERUSER)
|
||||||
logger.warning(AUTO_LOGIN_WARNING)
|
logger.warning(AUTO_LOGIN_WARNING)
|
||||||
return UserRead.model_validate(result, from_attributes=True)
|
return UserRead.model_validate(result, from_attributes=True)
|
||||||
else:
|
raise HTTPException(
|
||||||
raise HTTPException(
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
detail=AUTO_LOGIN_ERROR,
|
||||||
detail=AUTO_LOGIN_ERROR,
|
)
|
||||||
)
|
|
||||||
result = await check_key(db, query_param or header_param)
|
result = await check_key(db, query_param or header_param)
|
||||||
|
|
||||||
elif not query_param and not header_param:
|
elif not query_param and not header_param:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue