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
14 changes: 5 additions & 9 deletions src/main/java/com/mindee/InferenceParameters.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,9 +25,9 @@ public final class InferenceParameters {
/**
* IDs of webhooks to propagate the API response to (may be empty).
*/
private final List<String> webhookIds;
/*
* Asynchronous polling options.
private final String[] webhookIds;
/**
* Polling options. Set only if having timeout issues.
*/
private final AsyncPollingOptions pollingOptions;

Expand All @@ -52,7 +49,7 @@ public static final class Builder {
private final String modelId;
private boolean rag = false;
private String alias;
private List<String> webhookIds = Collections.emptyList();
private String[] webhookIds = new String[]{};
private AsyncPollingOptions pollingOptions = AsyncPollingOptions.builder().build();

private Builder(String modelId) {
Expand All @@ -72,12 +69,11 @@ public Builder alias(String alias) {
}

/** Provide IDs of webhooks to forward the API response to. */
public Builder webhookIds(List<String> webhookIds) {
public Builder webhookIds(String[] webhookIds) {
this.webhookIds = webhookIds;
return this;
}


public Builder pollingOptions(AsyncPollingOptions pollingOptions) {
this.pollingOptions = pollingOptions;
return this;
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/mindee/http/MindeeHttpApiV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,33 +248,33 @@ 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();
}


private HttpPost buildHttpPost(
String url,
InferenceParameters options
InferenceParameters params
) {
HttpPost post;
try {
Expand Down
54 changes: 43 additions & 11 deletions src/test/java/com/mindee/MindeeClientV2IT.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +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.builder(modelId).build();
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());
Expand All @@ -54,8 +64,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);
Expand Down Expand Up @@ -88,14 +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").build();
InferenceParameters params = InferenceParameters
.builder("INVALID_MODEL_ID")
.build();

MindeeHttpExceptionV2 ex = assertThrows(
MindeeHttpExceptionV2.class,
() -> mindeeClient.enqueueInference(source, options)
() -> 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, params)
);
assertEquals(422, ex.getStatus());
}
Expand All @@ -105,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);
Expand All @@ -118,8 +149,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);

Expand Down
Loading