From 03189047cd564f686c28caa0e31fb60ebff03a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Fri, 25 Jul 2025 15:46:32 +0200 Subject: [PATCH 1/2] :memo: explicit params in samples to ease documentation --- .../java/com/mindee/InferenceParameters.java | 4 ++-- .../java/com/mindee/MindeeClientV2IT.java | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/mindee/InferenceParameters.java b/src/main/java/com/mindee/InferenceParameters.java index 8d5bd671a..5be51c976 100644 --- a/src/main/java/com/mindee/InferenceParameters.java +++ b/src/main/java/com/mindee/InferenceParameters.java @@ -29,8 +29,8 @@ public final class InferenceParameters { * IDs of webhooks to propagate the API response to (may be empty). */ private final List webhookIds; - /* - * Asynchronous polling options. + /** + * Polling options. Set only if having timeout issues. */ private final AsyncPollingOptions pollingOptions; diff --git a/src/test/java/com/mindee/MindeeClientV2IT.java b/src/test/java/com/mindee/MindeeClientV2IT.java index 730fd3c18..ac586d956 100644 --- a/src/test/java/com/mindee/MindeeClientV2IT.java +++ b/src/test/java/com/mindee/MindeeClientV2IT.java @@ -30,8 +30,11 @@ void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedExcep LocalInputSource source = new LocalInputSource( new File("src/test/resources/file_types/pdf/multipage_cut-2.pdf")); - InferenceParameters options = - InferenceParameters.builder(modelId).build(); + InferenceParameters options = InferenceParameters + .builder(modelId) + .rag(false) + .alias("java-integration-test") + .build(); InferenceResponse response = mindeeClient.enqueueAndGetInference(source, options); @@ -54,8 +57,10 @@ void parseFile_filledSinglePage_mustSucceed() throws IOException, InterruptedExc LocalInputSource source = new LocalInputSource( new File("src/test/resources/products/financial_document/default_sample.jpg")); - InferenceParameters options = InferenceParameters.builder(modelId) + InferenceParameters options = InferenceParameters + .builder(modelId) .rag(false) + .alias("java-integration-test") .build(); InferenceResponse response = mindeeClient.enqueueAndGetInference(source, options); @@ -90,8 +95,9 @@ void invalidModel_mustThrowError() throws IOException { LocalInputSource source = new LocalInputSource( new File("src/test/resources/file_types/pdf/multipage_cut-2.pdf")); - InferenceParameters options = - InferenceParameters.builder("INVALID MODEL ID").build(); + InferenceParameters options = InferenceParameters + .builder("INVALID MODEL ID") + .build(); MindeeHttpExceptionV2 ex = assertThrows( MindeeHttpExceptionV2.class, @@ -118,8 +124,9 @@ void urlInputSource_mustNotRaiseErrors() throws IOException, InterruptedExceptio "https://upload.wikimedia.org/wikipedia/commons/1/1d/Blank_Page.pdf" ).build(); - InferenceParameters options = - InferenceParameters.builder(modelId).build(); + InferenceParameters options = InferenceParameters + .builder(modelId) + .build(); InferenceResponse response = mindeeClient.enqueueAndGetInference(urlSource, options); From 7c658cfabaf1bc3297728581d6119d9a7e467dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Fri, 25 Jul 2025 16:03:56 +0200 Subject: [PATCH 2/2] use array instead of list for webhook ids --- .../java/com/mindee/InferenceParameters.java | 10 ++--- .../java/com/mindee/http/MindeeHttpApiV2.java | 20 +++++----- .../java/com/mindee/MindeeClientV2IT.java | 39 +++++++++++++++---- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/mindee/InferenceParameters.java b/src/main/java/com/mindee/InferenceParameters.java index 5be51c976..f1f8e5292 100644 --- a/src/main/java/com/mindee/InferenceParameters.java +++ b/src/main/java/com/mindee/InferenceParameters.java @@ -1,8 +1,5 @@ package com.mindee; -import com.mindee.input.PageOptions; -import java.util.Collections; -import java.util.List; import java.util.Objects; import lombok.Data; import lombok.Getter; @@ -28,7 +25,7 @@ public final class InferenceParameters { /** * IDs of webhooks to propagate the API response to (may be empty). */ - private final List webhookIds; + private final String[] webhookIds; /** * Polling options. Set only if having timeout issues. */ @@ -52,7 +49,7 @@ public static final class Builder { private final String modelId; private boolean rag = false; private String alias; - private List webhookIds = Collections.emptyList(); + private String[] webhookIds = new String[]{}; private AsyncPollingOptions pollingOptions = AsyncPollingOptions.builder().build(); private Builder(String modelId) { @@ -72,12 +69,11 @@ public Builder alias(String alias) { } /** Provide IDs of webhooks to forward the API response to. */ - public Builder webhookIds(List webhookIds) { + public Builder webhookIds(String[] webhookIds) { this.webhookIds = webhookIds; return this; } - public Builder pollingOptions(AsyncPollingOptions pollingOptions) { this.pollingOptions = pollingOptions; return this; diff --git a/src/main/java/com/mindee/http/MindeeHttpApiV2.java b/src/main/java/com/mindee/http/MindeeHttpApiV2.java index 434841d4e..1589dea6f 100644 --- a/src/main/java/com/mindee/http/MindeeHttpApiV2.java +++ b/src/main/java/com/mindee/http/MindeeHttpApiV2.java @@ -248,25 +248,25 @@ private MindeeHttpExceptionV2 getHttpError(ClassicHttpResponse response) { private HttpEntity buildHttpBody( MultipartEntityBuilder builder, - InferenceParameters options + InferenceParameters params ) { - if (options.getAlias() != null) { + if (params.getAlias() != null) { builder.addTextBody( "alias", - options.getAlias().toLowerCase() + params.getAlias().toLowerCase() ); } - builder.addTextBody("model_id", options.getModelId()); - if (options.isRag()) { + builder.addTextBody("model_id", params.getModelId()); + if (params.isRag()) { builder.addTextBody("rag", "true"); } - if (options.getAlias() != null) { - builder.addTextBody("alias", options.getAlias()); + if (params.getAlias() != null) { + builder.addTextBody("alias", params.getAlias()); } - if (!options.getWebhookIds().isEmpty()) { - builder.addTextBody("webhook_ids", String.join(",", options.getWebhookIds())); + if (params.getWebhookIds().length > 0) { + builder.addTextBody("webhook_ids", String.join(",", params.getWebhookIds())); } return builder.build(); } @@ -274,7 +274,7 @@ private HttpEntity buildHttpBody( private HttpPost buildHttpPost( String url, - InferenceParameters options + InferenceParameters params ) { HttpPost post; try { diff --git a/src/test/java/com/mindee/MindeeClientV2IT.java b/src/test/java/com/mindee/MindeeClientV2IT.java index ac586d956..4fd03ee1b 100644 --- a/src/test/java/com/mindee/MindeeClientV2IT.java +++ b/src/test/java/com/mindee/MindeeClientV2IT.java @@ -30,13 +30,20 @@ void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedExcep LocalInputSource source = new LocalInputSource( new File("src/test/resources/file_types/pdf/multipage_cut-2.pdf")); - InferenceParameters options = InferenceParameters + InferenceParameters params = InferenceParameters .builder(modelId) .rag(false) .alias("java-integration-test") + .pollingOptions( + AsyncPollingOptions.builder() + .initialDelaySec(3.0) + .intervalSec(1.5) + .maxRetries(80) + .build() + ) .build(); - InferenceResponse response = mindeeClient.enqueueAndGetInference(source, options); + InferenceResponse response = mindeeClient.enqueueAndGetInference(source, params); assertNotNull(response); assertNotNull(response.getInference()); @@ -93,15 +100,33 @@ void parseFile_filledSinglePage_mustSucceed() throws IOException, InterruptedExc @DisplayName("Invalid model ID – enqueue must raise 422") void invalidModel_mustThrowError() throws IOException { LocalInputSource source = new LocalInputSource( - new File("src/test/resources/file_types/pdf/multipage_cut-2.pdf")); + new File("src/test/resources/file_types/pdf/blank_1.pdf")); - InferenceParameters options = InferenceParameters - .builder("INVALID MODEL ID") + InferenceParameters params = InferenceParameters + .builder("INVALID_MODEL_ID") + .build(); + + MindeeHttpExceptionV2 ex = assertThrows( + MindeeHttpExceptionV2.class, + () -> mindeeClient.enqueueInference(source, params) + ); + assertEquals(422, ex.getStatus()); + } + + @Test + @DisplayName("Invalid webhook ID – enqueue must raise 422") + void invalidWebhook_mustThrowError() throws IOException { + LocalInputSource source = new LocalInputSource( + new File("src/test/resources/file_types/pdf/blank_1.pdf")); + + InferenceParameters params = InferenceParameters + .builder(modelId) + .webhookIds(new String[]{"INVALID_WEBHOOK_ID"}) .build(); MindeeHttpExceptionV2 ex = assertThrows( MindeeHttpExceptionV2.class, - () -> mindeeClient.enqueueInference(source, options) + () -> mindeeClient.enqueueInference(source, params) ); assertEquals(422, ex.getStatus()); } @@ -111,7 +136,7 @@ void invalidModel_mustThrowError() throws IOException { void invalidJob_mustThrowError() { MindeeHttpExceptionV2 ex = assertThrows( MindeeHttpExceptionV2.class, - () -> mindeeClient.getInference("not-a-valid-job-ID") + () -> mindeeClient.getInference("INVALID_JOB_ID") ); assertEquals(422, ex.getStatus()); assertNotNull(ex);