Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -127,6 +137,7 @@ public class VlmModelApi {
* <li>{@code prompt(String)} - Set the prompt text</li>
* <li>{@code scale(Integer)} - Set the image scale factor</li>
* <li>{@code responseFormat(ResponseFormat)} - Set the response format</li>
* <li>{@code temperature(Double)} - Set the temperature</li>
* </ul>
*/
public static class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ public class VlmModelLocal {
@lombok.Singular("extraGenerationConfig")
private Map<String, Object> 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.
Expand All @@ -104,6 +114,7 @@ public class VlmModelLocal {
* <li>{@code transformersModelType(TransformersModelType)} - Set the transformers model type</li>
* <li>{@code extraGenerationConfig(String, Object)} - Add a single config entry (use with @Singular)</li>
* <li>{@code extraGenerationConfig(Map<String, Object>)} - Set the generation configuration map</li>
* <li>{@code temperature(Double)} - Set the temperature</li>
* </ul>
*/
public static class Builder {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Object> headers = Map.of("Authorization", "Bearer token123");
Map<String, Object> 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<String, Object> headers = new HashMap<>(Map.of("Authorization", "Bearer original"));
Map<String, Object> 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");
}

}
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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<String, Object> 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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/src/doc/docs/whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down