diff --git a/docling_serve/__main__.py b/docling_serve/__main__.py index 1b4f2e0..38b0f7e 100644 --- a/docling_serve/__main__.py +++ b/docling_serve/__main__.py @@ -30,7 +30,7 @@ logger = logging.getLogger(__name__) def version_callback(value: bool) -> None: if value: - docling_serve_version = importlib.metadata.version("docling_serve") + docling_serve_version = importlib.metadata.version("docling-serve") docling_jobkit_version = importlib.metadata.version("docling-jobkit") docling_version = importlib.metadata.version("docling") docling_core_version = importlib.metadata.version("docling-core") diff --git a/docling_serve/app.py b/docling_serve/app.py index 2774416..4fb4eef 100644 --- a/docling_serve/app.py +++ b/docling_serve/app.py @@ -76,7 +76,7 @@ from docling_serve.datamodel.responses import ( TaskStatusResponse, WebsocketMessage, ) -from docling_serve.helper_functions import FormDepends +from docling_serve.helper_functions import DOCLING_VERSIONS, FormDepends from docling_serve.orchestrator_factory import get_async_orchestrator from docling_serve.response_preparation import prepare_response from docling_serve.settings import docling_serve_settings @@ -437,6 +437,16 @@ def create_app(): # noqa: C901 def api_check() -> HealthCheckResponse: return HealthCheckResponse() + # Docling versions + @app.get("/version", tags=["health"]) + def version_info() -> dict: + if not docling_serve_settings.show_version_info: + raise HTTPException( + status_code=status.HTTP_403_FORBIDDEN, + detail="Forbidden. The server is configured for not showing version details.", + ) + return DOCLING_VERSIONS + # Convert a document from URL(s) @app.post( "/v1/convert/source", diff --git a/docling_serve/helper_functions.py b/docling_serve/helper_functions.py index 8e656cc..e1064d6 100644 --- a/docling_serve/helper_functions.py +++ b/docling_serve/helper_functions.py @@ -1,11 +1,25 @@ +import importlib.metadata import inspect import json +import platform import re +import sys from typing import Union, get_args, get_origin from fastapi import Depends, Form from pydantic import BaseModel, TypeAdapter +DOCLING_VERSIONS = { + "docling-serve": importlib.metadata.version("docling-serve"), + "docling-jobkit": importlib.metadata.version("docling-jobkit"), + "docling": importlib.metadata.version("docling"), + "docling-core": importlib.metadata.version("docling-core"), + "docling-ibm-models": importlib.metadata.version("docling-ibm-models"), + "docling-parse": importlib.metadata.version("docling-parse"), + "python": f"{sys.implementation.cache_tag} ({platform.python_version()})", + "plaform": platform.platform(), +} + def is_pydantic_model(type_): try: diff --git a/docling_serve/settings.py b/docling_serve/settings.py index 4981a3e..0ee088a 100644 --- a/docling_serve/settings.py +++ b/docling_serve/settings.py @@ -50,6 +50,7 @@ class DoclingServeSettings(BaseSettings): options_cache_size: int = 2 enable_remote_services: bool = False allow_external_plugins: bool = False + show_version_info: bool = True api_key: str = "" diff --git a/docs/configuration.md b/docs/configuration.md index 9e54538..3d4c112 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -39,6 +39,7 @@ THe following table describes the options to configure the Docling Serve app. | | `DOCLING_SERVE_STATIC_PATH` | unset | If set to a valid directory, the static assets for the docs and UI will be loaded from this path | | | `DOCLING_SERVE_SCRATCH_PATH` | | If set, this directory will be used as scratch workspace, e.g. storing the results before they get requested. If unset, a temporary created is created for this purpose. | | `--enable-ui` | `DOCLING_SERVE_ENABLE_UI` | `false` | Enable the demonstrator UI. | +| | `DOCLING_SERVE_SHOW_VERSION_INFO` | `true` | If enabled, the `/version` endpoint will provide the Docling package versions, otherwise it will return a forbidden 403 error. | | | `DOCLING_SERVE_ENABLE_REMOTE_SERVICES` | `false` | Allow pipeline components making remote connections. For example, this is needed when using a vision-language model via APIs. | | | `DOCLING_SERVE_ALLOW_EXTERNAL_PLUGINS` | `false` | Allow the selection of third-party plugins. | | | `DOCLING_SERVE_SINGLE_USE_RESULTS` | `true` | If true, results can be accessed only once. If false, the results accumulate in the scratch directory. |