diff --git a/docling/cli/main.py b/docling/cli/main.py index b0204151..c87e311f 100644 --- a/docling/cli/main.py +++ b/docling/cli/main.py @@ -532,7 +532,9 @@ def convert( backend=backend, # pdf_backend ) elif pipeline == PdfPipeline.VLM: - pipeline_options = VlmPipelineOptions() + pipeline_options = VlmPipelineOptions( + enable_remote_services=enable_remote_services, + ) if vlm_model == VlmModelType.GRANITE_VISION: pipeline_options.vlm_options = granite_vision_vlm_conversion_options diff --git a/docling/models/api_vlm_model.py b/docling/models/api_vlm_model.py index 8562bd14..95201224 100644 --- a/docling/models/api_vlm_model.py +++ b/docling/models/api_vlm_model.py @@ -3,6 +3,7 @@ from typing import Iterable from docling.datamodel.base_models import Page, VlmPrediction from docling.datamodel.document import ConversionResult from docling.datamodel.pipeline_options import ApiVlmOptions +from docling.exceptions import OperationNotAllowed from docling.models.base_model import BasePageModel from docling.utils.api_image_request import api_image_request from docling.utils.profiling import TimeRecorder @@ -13,11 +14,19 @@ class ApiVlmModel(BasePageModel): def __init__( self, enabled: bool, + enable_remote_services: bool, vlm_options: ApiVlmOptions, ): self.enabled = enabled self.vlm_options = vlm_options if self.enabled: + if not enable_remote_services: + raise OperationNotAllowed( + "Connections to remote services is only allowed when set explicitly. " + "pipeline_options.enable_remote_services=True, or using the CLI " + "--enable-remote-services." + ) + self.timeout = self.vlm_options.timeout self.prompt_content = ( f"This is a page from a document.\n{self.vlm_options.prompt}" diff --git a/docling/pipeline/vlm_pipeline.py b/docling/pipeline/vlm_pipeline.py index c1504be3..79279fd0 100644 --- a/docling/pipeline/vlm_pipeline.py +++ b/docling/pipeline/vlm_pipeline.py @@ -64,6 +64,7 @@ class VlmPipeline(PaginatedPipeline): self.build_pipe = [ ApiVlmModel( enabled=True, # must be always enabled for this pipeline to make sense. + enable_remote_services=self.pipeline_options.enable_remote_services, vlm_options=cast(ApiVlmOptions, self.pipeline_options.vlm_options), ), ] diff --git a/docs/examples/vlm_pipeline_api_model.py b/docs/examples/vlm_pipeline_api_model.py index bc71af38..33fb72a2 100644 --- a/docs/examples/vlm_pipeline_api_model.py +++ b/docs/examples/vlm_pipeline_api_model.py @@ -74,7 +74,7 @@ def main(): input_doc_path = Path("./tests/data/pdf/2305.03393v1-pg9.pdf") pipeline_options = VlmPipelineOptions( - # enable_remote_services=True # <-- this is required! + enable_remote_services=True # <-- this is required! ) # The ApiVlmOptions() allows to interface with APIs supporting