diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/ConvertDocumentOptions.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/ConvertDocumentOptions.java index 781502f6..6e69600a 100644 --- a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/ConvertDocumentOptions.java +++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/ConvertDocumentOptions.java @@ -398,7 +398,7 @@ public class ConvertDocumentOptions { @JsonProperty("vlm_pipeline_model_local") @Deprecated(since = "0.7.3") @Nullable - private String vlmPipelineModelLocal; + private VlmModelLocal vlmPipelineModelLocal; /** * API details for using a vision-language model for the vlm pipeline. This parameter is mutually exclusive with vlm_pipeline_model_local and vlm_pipeline_model. @@ -410,7 +410,7 @@ public class ConvertDocumentOptions { @JsonProperty("vlm_pipeline_model_api") @Deprecated(since = "0.7.3") @Nullable - private String vlmPipelineModelApi; + private VlmModelApi vlmPipelineModelApi; /** * Preset id for the VLM pipeline, for example {@code default} or {@code granite_docling}. Use {@code default} for the stable, deployment-controlled configuration. Mutually diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/VlmModelApi.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/VlmModelApi.java index 7d980795..4c09c182 100644 --- a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/VlmModelApi.java +++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/VlmModelApi.java @@ -111,6 +111,16 @@ public class VlmModelApi { @Nullable private ResponseFormat responseFormat; + /** + * Temperature parameter controlling the reproducibility of the result. + * + * @param temperature the temperature, or null if not specified + * @return the temperature, or null if not specified + */ + @JsonProperty("temperature") + @Nullable + private Double temperature; + /** * Builder for creating {@link VlmModelApi} instances. * Generated by Lombok's {@code @Builder} annotation. @@ -127,6 +137,7 @@ public class VlmModelApi { *
  • {@code prompt(String)} - Set the prompt text
  • *
  • {@code scale(Integer)} - Set the image scale factor
  • *
  • {@code responseFormat(ResponseFormat)} - Set the response format
  • + *
  • {@code temperature(Double)} - Set the temperature
  • * */ public static class Builder { diff --git a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/VlmModelLocal.java b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/VlmModelLocal.java index 113e290a..facb69ff 100644 --- a/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/VlmModelLocal.java +++ b/docling-serve/docling-serve-api/src/main/java/ai/docling/serve/api/convert/request/options/VlmModelLocal.java @@ -90,6 +90,16 @@ public class VlmModelLocal { @lombok.Singular("extraGenerationConfig") private Map extraGenerationConfig; + /** + * Temperature parameter controlling the reproducibility of the result. + * + * @param temperature the temperature, or null if not specified + * @return the temperature, or null if not specified + */ + @JsonProperty("temperature") + @Nullable + private Double temperature; + /** * Builder for creating {@link VlmModelLocal} instances. * Generated by Lombok's {@code @Builder} annotation. @@ -104,6 +114,7 @@ public class VlmModelLocal { *
  • {@code transformersModelType(TransformersModelType)} - Set the transformers model type
  • *
  • {@code extraGenerationConfig(String, Object)} - Add a single config entry (use with @Singular)
  • *
  • {@code extraGenerationConfig(Map)} - Set the generation configuration map
  • + *
  • {@code temperature(Double)} - Set the temperature
  • * */ public static class Builder { diff --git a/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/request/options/VlmModelApiTests.java b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/request/options/VlmModelApiTests.java new file mode 100644 index 00000000..81010abd --- /dev/null +++ b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/request/options/VlmModelApiTests.java @@ -0,0 +1,90 @@ +package ai.docling.serve.api.convert.request.options; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.net.URI; +import java.time.Duration; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +/** + * Unit tests for {@link VlmModelApi}. + */ +class VlmModelApiTests { + + @Test + void createApiWithAllFields() { + URI url = URI.create("https://api.example.com/v1/chat/completions"); + Map headers = Map.of("Authorization", "Bearer token123"); + Map params = Map.of("model", "granite-docling"); + Duration timeout = Duration.ofSeconds(60); + Integer concurrency = 4; + String prompt = "Convert this image to markdown"; + Integer scale = 2; + ResponseFormat responseFormat = ResponseFormat.MARKDOWN; + Double temperature = 0.2; + + VlmModelApi api = VlmModelApi.builder() + .url(url) + .headers(headers) + .params(params) + .timeout(timeout) + .concurrency(concurrency) + .prompt(prompt) + .scale(scale) + .responseFormat(responseFormat) + .temperature(temperature) + .build(); + + assertThat(api.getUrl()).isEqualTo(url); + assertThat(api.getHeaders()).isEqualTo(headers); + assertThat(api.getParams()).isEqualTo(params); + assertThat(api.getTimeout()).isEqualTo(timeout); + assertThat(api.getConcurrency()).isEqualTo(concurrency); + assertThat(api.getPrompt()).isEqualTo(prompt); + assertThat(api.getScale()).isEqualTo(scale); + assertThat(api.getResponseFormat()).isEqualTo(responseFormat); + assertThat(api.getTemperature()).isEqualTo(temperature); + } + + @Test + void createApiWithNoFieldsLeavesEverythingNull() { + VlmModelApi api = VlmModelApi.builder().build(); + + assertThat(api.getUrl()).isNull(); + assertThat(api.getHeaders()).isNotNull().isEmpty(); + assertThat(api.getParams()).isNotNull().isEmpty(); + assertThat(api.getTimeout()).isNull(); + assertThat(api.getConcurrency()).isNull(); + assertThat(api.getPrompt()).isNull(); + assertThat(api.getScale()).isNull(); + assertThat(api.getResponseFormat()).isNull(); + assertThat(api.getTemperature()).isNull(); + } + + @Test + void vlmModelApiIsImmutable() { + Map headers = new HashMap<>(Map.of("Authorization", "Bearer original")); + Map params = new HashMap<>(Map.of("model", "original-model")); + + VlmModelApi api = VlmModelApi.builder() + .url(URI.create("https://api.example.com/v1/chat/completions")) + .headers(headers) + .params(params) + .build(); + + assertThat(api.getHeaders()).isEqualTo(headers); + assertThat(api.getParams()).isEqualTo(params); + + headers.put("X-Custom-Header", "modified"); + params.put("temperature", 0.8); + + assertThat(api.getHeaders()).hasSize(1); + assertThat(api.getHeaders().get("Authorization")).isEqualTo("Bearer original"); + assertThat(api.getParams()).hasSize(1); + assertThat(api.getParams().get("model")).isEqualTo("original-model"); + } + +} diff --git a/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/request/options/VlmModelLocalTests.java b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/request/options/VlmModelLocalTests.java new file mode 100644 index 00000000..15d9c919 --- /dev/null +++ b/docling-serve/docling-serve-api/src/test/java/ai/docling/serve/api/convert/request/options/VlmModelLocalTests.java @@ -0,0 +1,78 @@ +package ai.docling.serve.api.convert.request.options; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +/** + * Unit tests for {@link VlmModelLocal}. + */ +class VlmModelLocalTests { + + @Test + void createLocalWithAllFields() { + String repoId = "ibm-granite/granite-docling-258M"; + String prompt = "Convert this image to markdown"; + Integer scale = 2; + ResponseFormat responseFormat = ResponseFormat.DOCTAGS; + VlmModelLocal.InferenceFramework inferenceFramework = VlmModelLocal.InferenceFramework.TRANSFORMERS; + VlmModelLocal.TransformersModelType transformersModelType = VlmModelLocal.TransformersModelType.AUTOMODEL_VISION2SEQ; + Map extraGenerationConfig = Map.of("max_new_tokens", 4096); + Double temperature = 0.2; + + VlmModelLocal local = VlmModelLocal.builder() + .repoId(repoId) + .prompt(prompt) + .scale(scale) + .responseFormat(responseFormat) + .inferenceFramework(inferenceFramework) + .transformersModelType(transformersModelType) + .extraGenerationConfig(extraGenerationConfig) + .temperature(temperature) + .build(); + + assertThat(local.getRepoId()).isEqualTo(repoId); + assertThat(local.getPrompt()).isEqualTo(prompt); + assertThat(local.getScale()).isEqualTo(scale); + assertThat(local.getResponseFormat()).isEqualTo(responseFormat); + assertThat(local.getInferenceFramework()).isEqualTo(inferenceFramework); + assertThat(local.getTransformersModelType()).isEqualTo(transformersModelType); + assertThat(local.getExtraGenerationConfig()).isEqualTo(extraGenerationConfig); + assertThat(local.getTemperature()).isEqualTo(temperature); + } + + @Test + void createLocalWithNoFieldsLeavesEverythingNull() { + VlmModelLocal local = VlmModelLocal.builder().build(); + + assertThat(local.getRepoId()).isNull(); + assertThat(local.getPrompt()).isNull(); + assertThat(local.getScale()).isNull(); + assertThat(local.getResponseFormat()).isNull(); + assertThat(local.getInferenceFramework()).isNull(); + assertThat(local.getTransformersModelType()).isNull(); + assertThat(local.getExtraGenerationConfig()).isNotNull().isEmpty(); + assertThat(local.getTemperature()).isNull(); + } + + @Test + void vlmModelLocalIsImmutable() { + Map extraGenerationConfig = new HashMap<>(Map.of("max_new_tokens", 4096)); + + VlmModelLocal local = VlmModelLocal.builder() + .repoId("ibm-granite/granite-docling-258M") + .extraGenerationConfig(extraGenerationConfig) + .build(); + + assertThat(local.getExtraGenerationConfig()).isEqualTo(extraGenerationConfig); + + extraGenerationConfig.put("temperature", 0.8); + + assertThat(local.getExtraGenerationConfig()).hasSize(1); + assertThat(local.getExtraGenerationConfig()).doesNotContainKey("temperature"); + } + +} diff --git a/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/AbstractDoclingServeClientTests.java b/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/AbstractDoclingServeClientTests.java index 96b483c7..82d2b845 100644 --- a/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/AbstractDoclingServeClientTests.java +++ b/docling-serve/docling-serve-client/src/test/java/ai/docling/serve/client/AbstractDoclingServeClientTests.java @@ -90,6 +90,8 @@ import ai.docling.serve.api.convert.request.options.ImageRefMode; import ai.docling.serve.api.convert.request.options.OutputFormat; import ai.docling.serve.api.convert.request.options.TableFormerMode; +import ai.docling.serve.api.convert.request.options.VlmModelApi; +import ai.docling.serve.api.convert.request.options.VlmModelLocal; import ai.docling.serve.api.convert.request.source.HttpSource; import ai.docling.serve.api.convert.request.source.S3Source; import ai.docling.serve.api.convert.request.target.PresignedUrlTarget; @@ -1176,6 +1178,64 @@ void shouldConvertSourceWithPutTargetSuccessfully() { ); } + // Regression test for https://github.com/docling-project/docling-java/issues/823: vlm_pipeline_model_local and + // vlm_pipeline_model_api used to be typed as String, which serialized to a JSON string where Docling Serve + // expects an object. + @Test + void shouldSendVlmPipelineModelLocalAndApiAsObjects() { + // A distinct source/target pair, not shared with another test, keeps this test's WireMock request count + // from colliding with another test's verify() when tests run in parallel. + var request = ConvertDocumentRequest.builder() + .source( + HttpSource.builder().url(URI.create("https://docs.arconia.io/arconia-cli/latest/development/dev/?vlm-pipeline-model-test")).build() + ) + .target( + PutTarget.builder().url(URI.create("https://github.com/docling-project/docling-java/save?vlm-pipeline-model-test")).build() + ) + .options( + ConvertDocumentOptions.builder() + .vlmPipelineModelLocal( + VlmModelLocal.builder() + .repoId("ibm-granite/granite-docling-258M") + .temperature(0.2) + .build() + ) + .vlmPipelineModelApi( + VlmModelApi.builder() + .url(URI.create("https://api.example.com/v1/chat/completions")) + .temperature(0.5) + .build() + ) + .build() + ).build(); + + var wireMockServer = getWiremockServer(); + + wireMockServer.stubFor( + post("/v1/convert/source") + .willReturn(okJson(""" + { + "processing_time": 7, + "num_converted": 10, + "num_succeeded": 5, + "num_failed": 5 + } + """)) + ); + + getDoclingClient(false, true).convertSource(request); + + wireMockServer.verify( + 1, postRequestedFor(urlPathEqualTo("/v1/convert/source")) + .withRequestBody( + matchingJsonPath("$.options.vlm_pipeline_model_local.repo_id", equalTo("ibm-granite/granite-docling-258M")) + .and(matchingJsonPath("$.options.vlm_pipeline_model_local.temperature", equalTo("0.2"))) + .and(matchingJsonPath("$.options.vlm_pipeline_model_api.url", equalTo("https://api.example.com/v1/chat/completions"))) + .and(matchingJsonPath("$.options.vlm_pipeline_model_api.temperature", equalTo("0.5"))) + ) + ); + } + @Test void shouldConvertS3SourceSuccessfully() { // Need to use Wiremock here rather than a "real" backend because Docling Serve requires kubeflow diff --git a/docs/src/doc/docs/whats-new.md b/docs/src/doc/docs/whats-new.md index 96392b1e..d80f88ad 100644 --- a/docs/src/doc/docs/whats-new.md +++ b/docs/src/doc/docs/whats-new.md @@ -41,6 +41,7 @@ Docling Java {{ gradle.project_version }} includes important breaking changes, a * **Logging a response that is not JSON no longer hides the error** — With both `logResponses()` and `prettyPrint()` enabled, a response body that is not JSON, such as an error page from a gateway or proxy in front of `docling-serve`, made the client fail with a raw Jackson exception while it was logging the response, so the status code and body were lost. The body is now logged as it is, and the request reports the usual `DoclingServeClientException`. The `readValue(String, Class)` method that subclasses of `DoclingServeClient` implement must now throw the new `JsonReadException`, with the failure of the JSON library as its cause, when the text is not valid JSON or does not match the expected type. * **A `422` response without validation details is a `DoclingServeClientException`** — A `422` response whose body is a JSON object without any validation details, such as `{}`, `{"detail": []}` or an error object from a gateway or proxy in front of `docling-serve`, used to throw a `ValidationException` with an empty `ValidationError` and a blank message. It now throws a `DoclingServeClientException` with the status code and the response body, like any other error response. Only a `422` response that carries validation details throws a `ValidationException`. * **A `422` response whose body is not JSON at all no longer loses its status code and body** — A `422` from something other than `docling-serve`, such as a gateway that returns an HTML or plain-text error page, made `readValue` throw before the client could fall back, replacing the real error with a raw parse failure. That parse failure (a `JsonReadException`) is now caught and treated the same as a `422` without validation details: a `DoclingServeClientException` carrying the status code and the response body. A failure that is not a `JsonReadException`, such as a broken custom deserializer, still propagates unchanged. +* **Fix: `vlmPipelineModelLocal` and `vlmPipelineModelApi` are now typed as `VlmModelLocal` and `VlmModelApi`** — These two deprecated `ConvertDocumentOptions` properties were declared as `String` since this library's first release, so a caller could never actually set a local or API model through them: Docling Serve expects an object, and a `String` serializes to a JSON string instead. They now use the existing `VlmModelLocal` and `VlmModelApi` types, which were already fully modeled but never wired up. Both types also gain a `temperature` field, mirroring a `docling-jobkit` field they were missing. ### 0.6.6