Skip to content

Commit f9e9542

Browse files
authored
✨ Add support for all utility models (#301)
1 parent 981e2df commit f9e9542

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1440
-126
lines changed

.github/workflows/_test-code-samples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
1313
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
1414
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
15+
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
1516

1617
jobs:
1718
test_sample_code:

.github/workflows/_test-integrations.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ on:
44
workflow_call:
55
workflow_dispatch:
66

7+
env:
8+
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
9+
WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }}
10+
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
11+
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
12+
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
13+
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
14+
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
15+
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
16+
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
17+
718
jobs:
819
integration_tests:
920
name: Run Integration Tests
@@ -31,11 +42,5 @@ jobs:
3142
cache: "maven"
3243

3344
- name: Verify with Maven
34-
env:
35-
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
36-
WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }}
37-
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
38-
MINDEE_V2_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
39-
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
4045
run: |
4146
mvn clean test-compile failsafe:integration-test failsafe:verify

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ src-lomboked
55

66
# test jshell file
77
_test.jsh
8-
SimpleMindeeClient.java
8+
SimpleMindeeClientV*
99

1010
# Compiled class file
1111
*.class
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import com.mindee.MindeeClientV2;
2+
import com.mindee.input.LocalInputSource;
3+
import com.mindee.v2.product.classification.ClassificationClassifier;
4+
import com.mindee.v2.product.classification.ClassificationResponse;
5+
import com.mindee.v2.product.classification.ClassificationResult;
6+
import com.mindee.v2.product.classification.params.ClassificationParameters;
7+
import java.io.File;
8+
import java.io.IOException;
9+
10+
public class SimpleMindeeClientV2 {
11+
12+
public static void main(String[] args)
13+
throws IOException, InterruptedException
14+
{
15+
String apiKey = "MY_API_KEY";
16+
String filePath = "/path/to/the/file.ext";
17+
String modelId = "MY_MODEL_ID";
18+
19+
// Init a new client
20+
MindeeClientV2 mindeeClient = new MindeeClientV2(apiKey);
21+
22+
// Set inference parameters
23+
// Note: modelId is mandatory.
24+
ClassificationParameters classificationParams = ClassificationParameters
25+
// ID of the model, required.
26+
.builder(modelId)
27+
.build();
28+
29+
// Load a file from disk
30+
LocalInputSource inputSource = new LocalInputSource(filePath);
31+
32+
// Send for processing
33+
ClassificationResponse response = mindeeClient.enqueueAndGetResult(
34+
ClassificationResponse.class,
35+
inputSource,
36+
classificationParams
37+
);
38+
39+
// Print a summary of the response
40+
System.out.println(response.getInference().toString());
41+
42+
// Access the classification result
43+
ClassificationResult result = response.getInference().getResult();
44+
ClassificationClassifier classification = result.getClassification();
45+
}
46+
}

docs/code_samples/v2_crop.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import com.mindee.MindeeClientV2;
2+
import com.mindee.input.LocalInputSource;
3+
import com.mindee.v2.product.crop.CropResponse;
4+
import com.mindee.v2.product.crop.CropResult;
5+
import com.mindee.v2.product.crop.params.CropParameters;
6+
import java.io.File;
7+
import java.io.IOException;
8+
9+
public class SimpleMindeeClientV2 {
10+
11+
public static void main(String[] args)
12+
throws IOException, InterruptedException
13+
{
14+
String apiKey = "MY_API_KEY";
15+
String filePath = "/path/to/the/file.ext";
16+
String modelId = "MY_MODEL_ID";
17+
18+
// Init a new client
19+
MindeeClientV2 mindeeClient = new MindeeClientV2(apiKey);
20+
21+
// Set inference parameters
22+
// Note: modelId is mandatory.
23+
CropParameters cropParams = CropParameters
24+
// ID of the model, required.
25+
.builder(modelId)
26+
.build();
27+
28+
// Load a file from disk
29+
LocalInputSource inputSource = new LocalInputSource(filePath);
30+
31+
// Send for processing
32+
CropResponse response = mindeeClient.enqueueAndGetResult(
33+
CropResponse.class,
34+
inputSource,
35+
cropParams
36+
);
37+
38+
// Print a summary of the response
39+
System.out.println(response.getInference().toString());
40+
41+
// Access the crop results
42+
CropResult result = response.getInference().getResult();
43+
}
44+
}

docs/code_samples/v2_extraction.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import com.mindee.MindeeClientV2;
22
import com.mindee.InferenceParameters;
33
import com.mindee.input.LocalInputSource;
44
import com.mindee.parsing.v2.InferenceResponse;
5-
import java.io.File;
5+
import com.mindee.parsing.v2.InferenceResult;
66
import java.io.IOException;
77

88
public class SimpleMindeeClientV2 {
@@ -19,7 +19,7 @@ public class SimpleMindeeClientV2 {
1919

2020
// Set inference parameters
2121
// Note: modelId is mandatory.
22-
InferenceParameters inferenceParams = InferenceParameters
22+
InferenceParameters extractionParams = InferenceParameters
2323
// ID of the model, required.
2424
.builder(modelId)
2525

@@ -38,17 +38,19 @@ public class SimpleMindeeClientV2 {
3838
.build();
3939

4040
// Load a file from disk
41-
LocalInputSource inputSource = new LocalInputSource(
42-
new File(filePath)
43-
);
41+
LocalInputSource inputSource = new LocalInputSource(filePath);
4442

4543
// Send for processing
46-
InferenceResponse response = mindeeClient.enqueueAndGetInference(
44+
InferenceResponse response = mindeeClient.enqueueAndGetResult(
45+
InferenceResponse.class,
4746
inputSource,
48-
inferenceParams
47+
extractionParams
4948
);
5049

5150
// Print a summary of the response
5251
System.out.println(response.getInference().toString());
52+
53+
// Access the result fields
54+
InferenceResult result = response.getInference().getResult();
5355
}
5456
}

docs/code_samples/v2_ocr.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import com.mindee.MindeeClientV2;
2+
import com.mindee.input.LocalInputSource;
3+
import com.mindee.v2.product.ocr.OcrResponse;
4+
import com.mindee.v2.product.ocr.OcrResult;
5+
import com.mindee.v2.product.ocr.params.OcrParameters;
6+
import java.io.File;
7+
import java.io.IOException;
8+
9+
public class SimpleMindeeClientV2 {
10+
11+
public static void main(String[] args)
12+
throws IOException, InterruptedException
13+
{
14+
String apiKey = "MY_API_KEY";
15+
String filePath = "/path/to/the/file.ext";
16+
String modelId = "MY_MODEL_ID";
17+
18+
// Init a new client
19+
MindeeClientV2 mindeeClient = new MindeeClientV2(apiKey);
20+
21+
// Set inference parameters
22+
// Note: modelId is mandatory.
23+
OcrParameters ocrParams = OcrParameters
24+
// ID of the model, required.
25+
.builder(modelId)
26+
.build();
27+
28+
// Load a file from disk
29+
LocalInputSource inputSource = new LocalInputSource(filePath);
30+
31+
// Send for processing
32+
OcrResponse response = mindeeClient.enqueueAndGetResult(
33+
OcrResponse.class,
34+
inputSource,
35+
ocrParams
36+
);
37+
38+
// Print a summary of the response
39+
System.out.println(response.getInference().toString());
40+
41+
// Access the result OCR pages
42+
OcrResult result = response.getInference().getResult();
43+
}
44+
}

docs/code_samples/v2_split.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import com.mindee.MindeeClientV2;
2+
import com.mindee.input.LocalInputSource;
3+
import com.mindee.v2.product.split.SplitResponse;
4+
import com.mindee.v2.product.split.SplitResult;
5+
import com.mindee.v2.product.split.params.SplitParameters;
6+
import java.io.File;
7+
import java.io.IOException;
8+
9+
public class SimpleMindeeClientV2 {
10+
11+
public static void main(String[] args)
12+
throws IOException, InterruptedException
13+
{
14+
String apiKey = "MY_API_KEY";
15+
String filePath = "/path/to/the/file.ext";
16+
String modelId = "MY_MODEL_ID";
17+
18+
// Init a new client
19+
MindeeClientV2 mindeeClient = new MindeeClientV2(apiKey);
20+
21+
// Set inference parameters
22+
// Note: modelId is mandatory.
23+
SplitParameters splitParams = SplitParameters
24+
// ID of the model, required.
25+
.builder(modelId)
26+
.build();
27+
28+
// Load a file from disk
29+
LocalInputSource inputSource = new LocalInputSource(filePath);
30+
31+
// Send for processing
32+
SplitResponse response = mindeeClient.enqueueAndGetResult(
33+
SplitResponse.class,
34+
inputSource,
35+
splitParams
36+
);
37+
38+
// Print a summary of the response
39+
System.out.println(response.getInference().toString());
40+
41+
// Access the split result
42+
SplitResult result = response.getInference().getResult();
43+
}
44+
}

src/main/java/com/mindee/InferenceParameters.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mindee;
22

33
import com.mindee.v2.clientOptions.BaseParameters;
4-
import java.util.Objects;
4+
import com.mindee.v2.http.ProductInfo;
55
import lombok.EqualsAndHashCode;
66
import lombok.Getter;
77
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
@@ -11,6 +11,7 @@
1111
*/
1212
@Getter
1313
@EqualsAndHashCode(callSuper = true)
14+
@ProductInfo(slug = "extraction")
1415
public final class InferenceParameters extends BaseParameters {
1516
/**
1617
* Enhance extraction accuracy with Retrieval-Augmented Generation.
@@ -96,21 +97,16 @@ public static Builder builder(String modelId) {
9697
/**
9798
* Fluent builder for {@link InferenceParameters}.
9899
*/
99-
public static final class Builder {
100-
101-
private final String modelId;
100+
public static final class Builder extends BaseParameters.BaseBuilder<Builder> {
102101
private Boolean rag = null;
103102
private Boolean rawText = null;
104103
private Boolean polygon = null;
105104
private Boolean confidence = null;
106-
private String alias;
107-
private String[] webhookIds = new String[] {};
108105
private String textContext;
109106
private String dataSchema;
110-
private AsyncPollingOptions pollingOptions = AsyncPollingOptions.builder().build();
111107

112-
private Builder(String modelId) {
113-
this.modelId = Objects.requireNonNull(modelId, "modelId must not be null");
108+
Builder(String modelId) {
109+
super(modelId);
114110
}
115111

116112
/** Enhance extraction accuracy with Retrieval-Augmented Generation. */
@@ -140,18 +136,6 @@ public Builder confidence(Boolean confidence) {
140136
return this;
141137
}
142138

143-
/** Set an alias for the uploaded document. */
144-
public Builder alias(String alias) {
145-
this.alias = alias;
146-
return this;
147-
}
148-
149-
/** Provide IDs of webhooks to forward the API response to. */
150-
public Builder webhookIds(String[] webhookIds) {
151-
this.webhookIds = webhookIds;
152-
return this;
153-
}
154-
155139
/** Provide additional text context used by the model during inference. */
156140
public Builder textContext(String textContext) {
157141
this.textContext = textContext;
@@ -164,12 +148,6 @@ public Builder dataSchema(String dataSchema) {
164148
return this;
165149
}
166150

167-
/** Set polling options. */
168-
public Builder pollingOptions(AsyncPollingOptions pollingOptions) {
169-
this.pollingOptions = pollingOptions;
170-
return this;
171-
}
172-
173151
/** Build an immutable {@link InferenceParameters} instance. */
174152
public InferenceParameters build() {
175153
return new InferenceParameters(

0 commit comments

Comments
 (0)