Skip to content

Commit 8e6c314

Browse files
committed
rework v2 parameters
1 parent c7c941c commit 8e6c314

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

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

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

33
import com.mindee.v2.clientOptions.BaseParameters;
4-
import java.util.Objects;
54
import lombok.EqualsAndHashCode;
65
import lombok.Getter;
76
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
@@ -96,21 +95,16 @@ public static Builder builder(String modelId) {
9695
/**
9796
* Fluent builder for {@link InferenceParameters}.
9897
*/
99-
public static final class Builder {
100-
101-
private final String modelId;
98+
public static final class Builder extends BaseParameters.BaseBuilder<Builder> {
10299
private Boolean rag = null;
103100
private Boolean rawText = null;
104101
private Boolean polygon = null;
105102
private Boolean confidence = null;
106-
private String alias;
107-
private String[] webhookIds = new String[] {};
108103
private String textContext;
109104
private String dataSchema;
110-
private AsyncPollingOptions pollingOptions = AsyncPollingOptions.builder().build();
111105

112-
private Builder(String modelId) {
113-
this.modelId = Objects.requireNonNull(modelId, "modelId must not be null");
106+
Builder(String modelId) {
107+
super(modelId);
114108
}
115109

116110
/** Enhance extraction accuracy with Retrieval-Augmented Generation. */
@@ -140,18 +134,6 @@ public Builder confidence(Boolean confidence) {
140134
return this;
141135
}
142136

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-
155137
/** Provide additional text context used by the model during inference. */
156138
public Builder textContext(String textContext) {
157139
this.textContext = textContext;
@@ -164,12 +146,6 @@ public Builder dataSchema(String dataSchema) {
164146
return this;
165147
}
166148

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

src/main/java/com/mindee/v2/clientOptions/BaseParameters.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mindee.v2.clientOptions;
22

33
import com.mindee.AsyncPollingOptions;
4+
import java.util.Objects;
45
import lombok.Data;
56
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
67

@@ -38,4 +39,39 @@ public MultipartEntityBuilder buildHttpBody(MultipartEntityBuilder builder) {
3839
}
3940
return builder;
4041
}
42+
43+
protected static abstract class BaseBuilder<T extends BaseBuilder<T>> {
44+
protected final String modelId;
45+
protected String alias;
46+
protected String[] webhookIds;
47+
protected AsyncPollingOptions pollingOptions;
48+
49+
@SuppressWarnings("unchecked")
50+
protected T self() {
51+
return (T) this;
52+
}
53+
54+
protected BaseBuilder(String modelId) {
55+
this.modelId = Objects.requireNonNull(modelId, "modelId must not be null");
56+
}
57+
58+
/** Set an alias for the uploaded document. */
59+
public T alias(String alias) {
60+
this.alias = alias;
61+
return self();
62+
}
63+
64+
/** Provide IDs of webhooks to forward the API response to. */
65+
public T webhookIds(String[] webhookIds) {
66+
this.webhookIds = webhookIds;
67+
return self();
68+
}
69+
70+
/** Set polling options. */
71+
public T pollingOptions(AsyncPollingOptions pollingOptions) {
72+
this.pollingOptions = pollingOptions;
73+
return self();
74+
}
75+
}
76+
4177
}

src/test/java/com/mindee/MindeeClientV2IT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void invalidJob_mustThrowError() {
212212
}
213213

214214
@Test
215-
@DisplayName("URL input source - A url param should not raise errors.")
215+
@DisplayName("URL input source - A URL param should not raise errors.")
216216
void urlInputSource_mustNotRaiseErrors() throws IOException, InterruptedException {
217217
URLInputSource urlSource = URLInputSource
218218
.builder(System.getenv("MINDEE_V2_SE_TESTS_BLANK_PDF_URL"))

0 commit comments

Comments
 (0)