41
41
public final class MindeeHttpApi extends MindeeApi {
42
42
43
43
private static final ObjectMapper mapper = new ObjectMapper ();
44
- private final Function <Endpoint , String > buildBaseUrl = this ::buildProductUrl ;
45
- private final Function <String , String > buildWorkflowBaseUrl = this ::buildWorkflowUrl ;
44
+ private final Function <Endpoint , String > buildProductPredicBasetUrl = this ::buildProductPredictBaseUrl ;
45
+ private final Function <String , String > buildWorkflowPredictBaseUrl = this ::buildWorkflowPredictBaseUrl ;
46
+ private final Function <String , String > buildWorkflowExecutionBaseUrl = this ::buildWorkflowExecutionUrl ;
46
47
/**
47
48
* The MindeeSetting needed to make the api call.
48
49
*/
@@ -53,24 +54,27 @@ public final class MindeeHttpApi extends MindeeApi {
53
54
*/
54
55
private final HttpClientBuilder httpClientBuilder ;
55
56
/**
56
- * The function used to generate the API endpoint URL.
57
+ * The function used to generate the synchronous API endpoint URL.
57
58
* Only needs to be set if the api calls need to be directed through internal URLs.
58
59
*/
59
60
private final Function <Endpoint , String > urlFromEndpoint ;
60
-
61
61
/**
62
- * The function used to generate the API endpoint URL for workflow execution calls .
62
+ * The function used to generate the asynchronous API endpoint URL for a product .
63
63
* Only needs to be set if the api calls need to be directed through internal URLs.
64
64
*/
65
65
private final Function <Endpoint , String > asyncUrlFromEndpoint ;
66
+ /**
67
+ * The function used to generate the asynchronous API endpoint URL for a workflow.
68
+ * Only needs to be set if the api calls need to be directed through internal URLs.
69
+ */
70
+ private final Function <String , String > asyncUrlFromWorkflow ;
66
71
/**
67
72
* The function used to generate the Job status URL for Async calls.
68
73
* Only needs to be set if the api calls need to be directed through internal URLs.
69
74
*/
70
75
private final Function <Endpoint , String > documentUrlFromEndpoint ;
71
-
72
76
/**
73
- * The function used to generate the Job status URL for Async calls.
77
+ * The function used to generate the Job status URL for workflow execution calls.
74
78
* Only needs to be set if the api calls need to be directed through internal URLs.
75
79
*/
76
80
private final Function <String , String > workflowUrlFromId ;
@@ -82,6 +86,7 @@ public MindeeHttpApi(MindeeSettings mindeeSettings) {
82
86
null ,
83
87
null ,
84
88
null ,
89
+ null ,
85
90
null
86
91
);
87
92
}
@@ -93,7 +98,8 @@ private MindeeHttpApi(
93
98
Function <Endpoint , String > urlFromEndpoint ,
94
99
Function <Endpoint , String > asyncUrlFromEndpoint ,
95
100
Function <Endpoint , String > documentUrlFromEndpoint ,
96
- Function <String , String > workflowUrlFromEndpoint
101
+ Function <String , String > workflowUrlFromEndpoint ,
102
+ Function <String , String > asyncUrlFromWorkflow
97
103
) {
98
104
this .mindeeSettings = mindeeSettings ;
99
105
@@ -106,26 +112,35 @@ private MindeeHttpApi(
106
112
if (urlFromEndpoint != null ) {
107
113
this .urlFromEndpoint = urlFromEndpoint ;
108
114
} else {
109
- this .urlFromEndpoint = buildBaseUrl .andThen ((url ) -> url .concat ("/predict" ));
115
+ this .urlFromEndpoint = buildProductPredicBasetUrl .andThen (
116
+ (url ) -> url .concat ("/predict" ));
117
+ }
118
+
119
+ if (asyncUrlFromWorkflow != null ) {
120
+ this .asyncUrlFromWorkflow = asyncUrlFromWorkflow ;
121
+ } else {
122
+ this .asyncUrlFromWorkflow = this .buildWorkflowPredictBaseUrl .andThen (
123
+ (url ) -> url .concat ("/predict_async" ));
110
124
}
111
125
112
126
if (asyncUrlFromEndpoint != null ) {
113
127
this .asyncUrlFromEndpoint = asyncUrlFromEndpoint ;
114
128
} else {
115
- this .asyncUrlFromEndpoint = this .urlFromEndpoint .andThen ((url ) -> url .concat ("_async" ));
129
+ this .asyncUrlFromEndpoint = this .buildProductPredicBasetUrl .andThen (
130
+ (url ) -> url .concat ("/predict_async" ));
116
131
}
117
132
118
133
if (documentUrlFromEndpoint != null ) {
119
134
this .documentUrlFromEndpoint = documentUrlFromEndpoint ;
120
135
} else {
121
- this .documentUrlFromEndpoint = this .buildBaseUrl .andThen (
136
+ this .documentUrlFromEndpoint = this .buildProductPredicBasetUrl .andThen (
122
137
(url ) -> url .concat ("/documents/queue/" ));
123
138
}
124
139
125
140
if (workflowUrlFromEndpoint != null ) {
126
141
this .workflowUrlFromId = workflowUrlFromEndpoint ;
127
142
} else {
128
- this .workflowUrlFromId = this .buildWorkflowBaseUrl ;
143
+ this .workflowUrlFromId = this .buildWorkflowExecutionBaseUrl ;
129
144
}
130
145
}
131
146
@@ -233,7 +248,12 @@ public <DocT extends Inference> AsyncPredictResponse<DocT> predictAsyncPost(
233
248
RequestParameters requestParameters
234
249
) throws IOException {
235
250
236
- String url = asyncUrlFromEndpoint .apply (endpoint );
251
+ String url ;
252
+ if (requestParameters .getPredictOptions ().getWorkflowId () != null ) {
253
+ url = asyncUrlFromWorkflow .apply (requestParameters .getPredictOptions ().getWorkflowId ());
254
+ } else {
255
+ url = asyncUrlFromEndpoint .apply (endpoint );
256
+ }
237
257
HttpPost post = buildHttpPost (url , requestParameters );
238
258
239
259
// required to register jackson date module format to deserialize
@@ -340,7 +360,7 @@ private <ResponseT extends ApiResponse> MindeeHttpException getHttpError(
340
360
return new MindeeHttpException (statusCode , message , details , errorCode );
341
361
}
342
362
343
- private String buildProductUrl (Endpoint endpoint ) {
363
+ private String buildProductPredictBaseUrl (Endpoint endpoint ) {
344
364
return this .mindeeSettings .getBaseUrl ()
345
365
+ "/products/"
346
366
+ endpoint .getAccountName ()
@@ -350,7 +370,11 @@ private String buildProductUrl(Endpoint endpoint) {
350
370
+ endpoint .getVersion ();
351
371
}
352
372
353
- private String buildWorkflowUrl (String workflowId ) {
373
+ private String buildWorkflowPredictBaseUrl (String workflowId ) {
374
+ return this .mindeeSettings .getBaseUrl () + "/workflows/" + workflowId ;
375
+ }
376
+
377
+ private String buildWorkflowExecutionUrl (String workflowId ) {
354
378
return this .mindeeSettings .getBaseUrl () + "/workflows/" + workflowId + "/executions" ;
355
379
}
356
380
@@ -388,7 +412,9 @@ private List<NameValuePair> buildPostParams(
388
412
if (Boolean .TRUE .equals (requestParameters .getPredictOptions ().getFullText ())) {
389
413
params .add (new BasicNameValuePair ("full_text_ocr" , "true" ));
390
414
}
391
- if (Boolean .TRUE .equals (requestParameters .getWorkflowOptions ().getRag ())) {
415
+ if (Boolean .TRUE .equals (requestParameters .getWorkflowOptions ().getRag ())
416
+ || Boolean .TRUE .equals (requestParameters .getPredictOptions ().getRag ())
417
+ ) {
392
418
params .add (new BasicNameValuePair ("rag" , "true" ));
393
419
}
394
420
return params ;
0 commit comments