-
Notifications
You must be signed in to change notification settings - Fork 8.7k
feat: Use LLM components in Docling #9770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
erichare
merged 8 commits into
langflow-ai:main
from
dolfim-ibm:feat-docling-bundle-using-lcllm
Sep 11, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d165f28
configure Docling bundle with LC LLM objects
dolfim-ibm 5193da6
cleanup old not used code
dolfim-ibm 0d1c14f
Merge remote-tracking branch 'upstream/main' into feat-docling-bundle…
dolfim-ibm b2ac95e
pin released docling plugin
dolfim-ibm 1df71aa
use generic pydantic serialization
dolfim-ibm 1df40c0
Apply suggestions from code review
dolfim-ibm 7a2ccbd
[autofix.ci] apply automated fixes
autofix-ci[bot] 3e02126
Merge branch 'main' into feat-docling-bundle-using-lcllm
erichare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,8 @@ | |
| from queue import Empty | ||
|
|
||
| from lfx.base.data import BaseFileComponent | ||
| from lfx.base.data.docling_utils import docling_worker | ||
| from lfx.inputs import DropdownInput | ||
| from lfx.base.data.docling_utils import _serialize_pydantic_model, docling_worker | ||
| from lfx.inputs import BoolInput, DropdownInput, HandleInput, StrInput | ||
| from lfx.schema import Data | ||
|
|
||
|
|
||
|
|
@@ -67,6 +67,26 @@ class DoclingInlineComponent(BaseFileComponent): | |
| real_time_refresh=False, | ||
| value="None", | ||
| ), | ||
| BoolInput( | ||
| name="do_picture_classification", | ||
| display_name="Picture classification", | ||
| info="If enabled, the Docling pipeline will classify the pictures type.", | ||
| value=False, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: I believe this is the default value for a BoolInput, so could be omitted if desired. |
||
| ), | ||
| HandleInput( | ||
| name="pic_desc_llm", | ||
| display_name="Picture description LLM", | ||
| info="If connected, the model to use for running the picture description task.", | ||
| input_types=["LanguageModel"], | ||
| required=False, | ||
| ), | ||
| StrInput( | ||
| name="pic_desc_prompt", | ||
| display_name="Picture description prompt", | ||
| value="Describe the image in three sentences. Be concise and accurate.", | ||
| info="The user prompt to use when invoking the model.", | ||
| advanced=True, | ||
| ), | ||
| # TODO: expose more Docling options | ||
| ] | ||
|
|
||
|
|
@@ -131,64 +151,37 @@ def _terminate_process_gracefully(self, proc, timeout_terminate: int = 10, timeo | |
|
|
||
| def process_files(self, file_list: list[BaseFileComponent.BaseFile]) -> list[BaseFileComponent.BaseFile]: | ||
| try: | ||
| from docling.datamodel.base_models import InputFormat | ||
| from docling.datamodel.pipeline_options import OcrOptions, PdfPipelineOptions, VlmPipelineOptions | ||
| from docling.document_converter import DocumentConverter, FormatOption, PdfFormatOption | ||
| from docling.models.factories import get_ocr_factory | ||
| from docling.pipeline.vlm_pipeline import VlmPipeline | ||
| from docling.document_converter import DocumentConverter # noqa: F401 | ||
| except ImportError as e: | ||
| msg = ( | ||
| "Docling is an optional dependency. Install with `uv pip install 'langflow[docling]'` or refer to the " | ||
| "documentation on how to install optional dependencies." | ||
| ) | ||
| raise ImportError(msg) from e | ||
|
|
||
| # Configure the standard PDF pipeline | ||
| def _get_standard_opts() -> PdfPipelineOptions: | ||
| pipeline_options = PdfPipelineOptions() | ||
| pipeline_options.do_ocr = self.ocr_engine != "None" | ||
| if pipeline_options.do_ocr: | ||
| ocr_factory = get_ocr_factory( | ||
| allow_external_plugins=False, | ||
| ) | ||
|
|
||
| ocr_options: OcrOptions = ocr_factory.create_options( | ||
| kind=self.ocr_engine, | ||
| ) | ||
| pipeline_options.ocr_options = ocr_options | ||
| return pipeline_options | ||
|
|
||
| # Configure the VLM pipeline | ||
| def _get_vlm_opts() -> VlmPipelineOptions: | ||
| return VlmPipelineOptions() | ||
|
|
||
| # Configure the main format options and create the DocumentConverter() | ||
| def _get_converter() -> DocumentConverter: | ||
| if self.pipeline == "standard": | ||
| pdf_format_option = PdfFormatOption( | ||
| pipeline_options=_get_standard_opts(), | ||
| ) | ||
| elif self.pipeline == "vlm": | ||
| pdf_format_option = PdfFormatOption(pipeline_cls=VlmPipeline, pipeline_options=_get_vlm_opts()) | ||
|
|
||
| format_options: dict[InputFormat, FormatOption] = { | ||
| InputFormat.PDF: pdf_format_option, | ||
| InputFormat.IMAGE: pdf_format_option, | ||
| } | ||
|
|
||
| return DocumentConverter(format_options=format_options) | ||
|
|
||
| file_paths = [file.path for file in file_list if file.path] | ||
|
|
||
| if not file_paths: | ||
| self.log("No files to process.") | ||
| return file_list | ||
|
|
||
| pic_desc_config: dict | None = None | ||
| if self.pic_desc_llm is not None: | ||
| pic_desc_config = _serialize_pydantic_model(self.pic_desc_llm) | ||
|
|
||
| ctx = get_context("spawn") | ||
| queue: Queue = ctx.Queue() | ||
| proc = ctx.Process( | ||
| target=docling_worker, | ||
| args=(file_paths, queue, self.pipeline, self.ocr_engine), | ||
| kwargs={ | ||
| "file_paths": file_paths, | ||
| "queue": queue, | ||
| "pipeline": self.pipeline, | ||
| "ocr_engine": self.ocr_engine, | ||
| "do_picture_classification": self.do_picture_classification, | ||
| "pic_desc_config": pic_desc_config, | ||
| "pic_desc_prompt": self.pic_desc_prompt, | ||
| }, | ||
| ) | ||
|
|
||
| result = None | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Harden deserialization: validate class path + robust errors.
Dynamic imports from unvalidated class paths are risky and brittle. Gate the module prefix, validate keys, and avoid KeyError/ValueError crashes.
📝 Committable suggestion
🤖 Prompt for AI Agents