From a212547d28d6588c65e52000dc7bc04f3f77e69e Mon Sep 17 00:00:00 2001 From: Michele Dolfi <97102151+dolfim-ibm@users.noreply.github.com> Date: Sun, 16 Mar 2025 09:03:22 +0100 Subject: [PATCH] fix: add warning when using incompatible parameters (#99) Signed-off-by: Michele Dolfi --- docling_serve/__main__.py | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/docling_serve/__main__.py b/docling_serve/__main__.py index 257807d..0055fa7 100644 --- a/docling_serve/__main__.py +++ b/docling_serve/__main__.py @@ -74,11 +74,37 @@ def callback( def _run( *, command: str, + # Docling serve parameters + artifacts_path: Path | None, + enable_ui: bool, ) -> None: server_type = "development" if command == "dev" else "production" console.print(f"Starting {server_type} server 🚀") + run_subprocess = ( + uvicorn_settings.workers is not None and uvicorn_settings.workers > 1 + ) or uvicorn_settings.reload + + if run_subprocess and docling_serve_settings.artifacts_path != artifacts_path: + err_console.print( + "\n[yellow]:warning: The server will run with reload or multiple workers. \n" + "The argument [bold]--artifacts-path[/bold] will be ignored, please set the value \n" + "using the environment variable [bold]DOCLING_SERVE_ARTIFACTS_PATH[/bold].[/yellow]" + ) + + if run_subprocess and docling_serve_settings.enable_ui != enable_ui: + err_console.print( + "\n[yellow]:warning: The server will run with reload or multiple workers. \n" + "The argument [bold]--enable-ui[/bold] will be ignored, please set the value \n" + "using the environment variable [bold]DOCLING_SERVE_ENABLE_UI[/bold].[/yellow]" + ) + + # Propagate the settings to the app settings + docling_serve_settings.artifacts_path = artifacts_path + docling_serve_settings.enable_ui = enable_ui + + # Print documentation url = f"http://{uvicorn_settings.host}:{uvicorn_settings.port}" url_docs = f"{url}/docs" url_ui = f"{url}/ui" @@ -99,6 +125,7 @@ def _run( console.print("") console.print("Logs:") + # Launch the server uvicorn.run( app="docling_serve.app:create_app", factory=True, @@ -187,11 +214,10 @@ def dev( uvicorn_settings.root_path = root_path uvicorn_settings.proxy_headers = proxy_headers - docling_serve_settings.artifacts_path = artifacts_path - docling_serve_settings.enable_ui = enable_ui - _run( command="dev", + artifacts_path=artifacts_path, + enable_ui=enable_ui, ) @@ -282,11 +308,10 @@ def run( uvicorn_settings.root_path = root_path uvicorn_settings.proxy_headers = proxy_headers - docling_serve_settings.artifacts_path = artifacts_path - docling_serve_settings.enable_ui = enable_ui - _run( command="run", + artifacts_path=artifacts_path, + enable_ui=enable_ui, )