mirror of
https://github.com/DS4SD/docling.git
synced 2025-07-27 04:24:45 +00:00
require flag for remote services
Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
This commit is contained in:
parent
414a6b7246
commit
8a75615b9b
@ -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
|
||||
|
@ -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}"
|
||||
|
@ -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),
|
||||
),
|
||||
]
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user